• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

kpilot

config_dialog_probe.cc

Go to the documentation of this file.
00001 /* KPilot
00002 **
00003 ** Copyright (C) 2004 Reinhold Kainhofer <reinhold@kainhofer.com>
00004 **
00005 ** This file defines the logic for the device probing dialog.
00006 */
00007 
00008 /*
00009 ** This program is free software; you can redistribute it and/or modify
00010 ** it under the terms of the GNU General Public License as published by
00011 ** the Free Software Foundation; either version 2 of the License, or
00012 ** (at your option) any later version.
00013 **
00014 ** This program is distributed in the hope that it will be useful,
00015 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00017 ** GNU General Public License for more details.
00018 **
00019 ** You should have received a copy of the GNU General Public License
00020 ** along with this program in a file called COPYING; if not, write to
00021 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00022 ** MA 02110-1301, USA.
00023 */
00024 
00025 /*
00026 ** Bug reports and questions can be sent to kde-pim@kde.org
00027 */
00028 
00029 #include "options.h"
00030 
00031 #include <QtCore/QMap>
00032 #include <QtCore/QTimer>
00033 #include <QtGui/QGroupBox>
00034 #include <QtGui/QLabel>
00035 #include <QtGui/QLayout>
00036 
00037 #include <kapplication.h>
00038 #include <kconfigskeleton.h>
00039 #include <kglobal.h>
00040 #include <klocale.h>
00041 #include <kmessagebox.h>
00042 #include <kprogressdialog.h>
00043 #include <kvbox.h>
00044 
00045 #include "kpilotdevicelink.h"
00046 #include "pilotSysInfo.h"
00047 #include "pilotUser.h"
00048 
00049 #include "kpilotConfig.h"
00050 #include "kpilot_daemon_interface.h"
00051 
00052 #include "config_dialog_probe.moc"
00053 
00054 /*
00055 We can't connect to /dev/ttyUSB0 and /dev/ttyUSB1 at the same time, because that
00056 will lock up kpilot completely. In particular, it gets a connection on /dev/ttyUSB0,
00057 which it processes, and while processing, a connection on USB1 is also detected.
00058 However, when kpilot gets 'round to process it, the link is already closed, and
00059 pi_connect hangs forever.
00060 
00061 Now, I split up the list of devices to probe into three list, one holding /dev/pilot,
00062 the second holding all /dev/xxx0 and /dev/xxx2 (e.g. /dev/ttyUSB0 and /dev/ttyUSB2),
00063 and finally a third holding the remaining /dev/xxx1 and /dev/xxx3 devices. Each of
00064 these three sets of devices is activated for a few seconds, and then the next set is
00065 probed. This way, I ensure that kpilot never listens on /dev/ttyUSB0 and /dev/ttyUSB1
00066 at the same time.
00067 
00068 Now the first detection works fine. However, it seems the Linux kernel has another
00069 problem with /dev/ttyUSB0. I have a Clie, which uses ttyUSB0, and as soon as the
00070 wizard tries to listen on ttyUSB1 (after it detected the handheld on ttyUSB0 already),
00071 the kernel writes a warning message to the syslog:
00072 visor ttyUSB1: Device lied about number of ports, please use a lower one.
00073 
00074 If I continue autodetection once again afterwards, the visor module kind of crashes.
00075 lsmod shows an impossible usage count for the module:
00076 
00077 reinhold@einstein:/kde/builddir$ lsmod
00078 Module                  Size  Used by
00079 visor                  17164  4294967294
00080 usbserial              30704  1 visor
00081 
00082 After that, the kernel doesn't detect the device ever again (until the computer is rebooted),
00083 and the module can't be unloaded.
00084 */
00085 
00086 
00087 ProbeDialog::ProbeDialog(QWidget *parent, const char *n) :
00088     KDialog(parent),
00089     fResultsGroup(0L),
00090     fStatusLabel(0L),
00091     fUserNameLabel(0L),
00092     fDeviceNameLabel(0L),
00093     fProgress(0L),
00094     fDetected(false), fUserName(), fDeviceName()
00095 {
00096     if (n)
00097     {
00098         setObjectName(n);
00099     }
00100     setCaption(i18n("Autodetecting Your Handheld"));
00101     setButtonText(Ok,i18n("Restart Detection"));
00102     setButtons(Ok|Cancel|User1);
00103     setDefaultButton(Cancel);
00104     setModal(true);
00105     FUNCTIONSETUP;
00106 
00107     KVBox *mainWidget = new KVBox();
00108     setMainWidget(mainWidget);
00109 
00110     QLabel *infoText = new QLabel( i18n( "KPilot is now trying to automatically detect the device of your handheld. Please press the hotsync button if you have not done so already." ), mainWidget );
00111     infoText->setObjectName( "fInfoText" );
00112     infoText->setWordWrap( true );
00113 
00114     QGroupBox *statusGroup = new QGroupBox( i18n("Status"), mainWidget );
00115     QHBoxLayout *statusGroupLayout = new QHBoxLayout;
00116     statusGroup->setLayout( statusGroupLayout );
00117 
00118     fStatusLabel = new QLabel( i18n("Autodetection not yet started..."), statusGroup );
00119     statusGroupLayout->addWidget( fStatusLabel );
00120 
00121     fProgress = new QProgressBar( statusGroup );
00122     fProgress->setMaximum(100);
00123     statusGroupLayout->addWidget( fProgress );
00124 
00125 
00126 
00127     fResultsGroup = new QGroupBox( i18n( "Detected Values" ), mainWidget );
00128     fResultsGroup->setEnabled( false );
00129     QGridLayout *resultsGroupLayout = new QGridLayout;
00130     fResultsGroup->setLayout( resultsGroupLayout );
00131 
00132     QLabel *userLabel = new QLabel( i18n( "Handheld user:" ), fResultsGroup );
00133     resultsGroupLayout->addWidget( userLabel, 0, 0 );
00134 
00135     QLabel *deviceLabel = new QLabel( i18n( "Device:" ), fResultsGroup );
00136     resultsGroupLayout->addWidget( deviceLabel, 1, 0 );
00137 
00138     fUserNameLabel = new QLabel( i18n("[Not yet known]"), fResultsGroup );
00139     fUserNameLabel->setObjectName( "fUser" );
00140     resultsGroupLayout->addWidget( fUserNameLabel, 0, 1 );
00141 
00142     fDeviceNameLabel = new QLabel( i18n("[Not yet known]"), fResultsGroup );
00143     fDeviceNameLabel->setObjectName( "fDevice" );
00144     resultsGroupLayout->addWidget( fDeviceNameLabel, 1, 1 );
00145 
00146 
00147     resize( QSize(459, 298).expandedTo(minimumSizeHint()) );
00148     enableButtonOk(false);
00149 
00150     fDevicesToProbe[0] << "/dev/pilot";
00151     fDevicesToProbe[1] << "/dev/ttyS0"<< "/dev/ttyS2"
00152                     << "/dev/tts/0"<< "/dev/tts/2"
00153                     << "/dev/ttyUSB0"<< "/dev/ttyUSB2"
00154                     << "/dev/usb/tts/0"<< "/dev/usb/tts/2"
00155                     << "/dev/cuaa0"<< "/dev/cuaa2"
00156             << "/dev/cuad0"<< "/dev/cuad2"
00157                     << "/dev/ucom0"<< "/dev/ucom2";
00158     fDevicesToProbe[2] << "/dev/ttyS1"<< "/dev/ttyS3"
00159                     << "/dev/tts/1"<< "/dev/tts/3"
00160                     << "/dev/ttyUSB1"<< "/dev/ttyUSB3"
00161                     << "/dev/usb/tts/1"<< "/dev/usb/tts/3"
00162                     << "/dev/cuaa1"<< "/dev/cuaa3"
00163             << "/dev/cuad1"<< "/dev/cuad3"
00164                     << "/dev/ucom1"<< "/dev/ucom3";
00165 
00166     fProcessEventsTimer = new QTimer( this );
00167     fTimeoutTimer = new QTimer( this );
00168     fProgressTimer = new QTimer( this );
00169     fRotateLinksTimer = new QTimer( this );
00170     connect( fProcessEventsTimer, SIGNAL(timeout()), this, SLOT(processEvents()) );
00171     connect( fTimeoutTimer, SIGNAL(timeout()), this, SLOT(timeout()) );
00172     connect( fProgressTimer, SIGNAL(timeout()), this, SLOT( progress()) );
00173     connect( fRotateLinksTimer, SIGNAL(timeout()), this, SLOT( detect()) );
00174     connect( this, SIGNAL(finished()), this, SLOT(disconnectDevices()) );
00175 }
00176 
00177 ProbeDialog::~ProbeDialog()
00178 {
00179     FUNCTIONSETUP;
00180 }
00181 
00182 void ProbeDialog::processEvents()
00183 {
00184     FUNCTIONSETUP;
00185     KApplication::kApplication()->processEvents();
00186 }
00187 
00188 void ProbeDialog::progress()
00189 {
00190     fProgress->setValue(fProgress->value()+1);
00191 }
00192 
00193 int ProbeDialog::exec()
00194 {
00195     fDetected = false;
00196     fUserName.clear();
00197     fDeviceName.clear();
00198     QTimer::singleShot( 0, this, SLOT( startDetection() ) );
00199     return KDialog::exec();
00200 }
00201 
00202 void ProbeDialog::startDetection()
00203 {
00204     FUNCTIONSETUP;
00205 
00206     disconnectDevices();
00207     fProgress->setValue(0);
00208     fStatusLabel->setText( i18n("Starting detection...") );
00209     OrgKdeKpilotDaemonInterface *daemonInterface = new OrgKdeKpilotDaemonInterface("org.kde.kpilot.daemon", "/Daemon", QDBusConnection::sessionBus());
00210     if (daemonInterface) {
00211         daemonInterface->stopListening();
00212     }
00213     KPILOT_DELETE(daemonInterface);
00214     fTimeoutTimer->setSingleShot( true );
00215     fTimeoutTimer->start( 30000 );
00216     fProcessEventsTimer->setSingleShot( false );
00217     fProcessEventsTimer->start( 100 );
00218     fProgressTimer->setSingleShot( false );
00219     fProgressTimer->start( 300 );
00220 
00221     KPilotDeviceLink*link;
00222     for (int i=0; i<3; ++i)
00223     {
00224         QStringList::iterator end(fDevicesToProbe[i].end());
00225         for (QStringList::iterator it=fDevicesToProbe[i].begin(); it!=end; ++it)
00226         {
00227             link = new KPilotDeviceLink();
00228             link->setDevice((*it));
00229             DEBUGKPILOT << "new kpilotDeviceLink for " << (*it);
00230             fDeviceLinks[i].append( link );
00231             connect( link, SIGNAL(deviceReady(KPilotLink*)), this, SLOT(connection(KPilotLink*)) );
00232             processEvents();
00233         }
00234     }
00235     fStatusLabel->setText( i18n("Waiting for handheld to connect...") );
00236     fProbeDevicesIndex=0;
00237 
00238     detect();
00239     fRotateLinksTimer->setSingleShot( false );
00240     fRotateLinksTimer->start( 3000 );
00241 }
00242 
00243 
00244 void ProbeDialog::detect(int i)
00245 {
00246     FUNCTIONSETUP;
00247 
00248     fProbeDevicesIndex = i;
00249     PilotLinkList::iterator end(fDeviceLinks[fProbeDevicesIndex].end());
00250 
00251     for (PilotLinkList::iterator it=fDeviceLinks[fProbeDevicesIndex].begin(); it!=end; ++it)
00252     {
00253         if (*it)
00254         {
00255             (*it)->reset();
00256         }
00257     }
00258 }
00259 
00260 void ProbeDialog::detect()
00261 {
00262     detect( (fProbeDevicesIndex+1)%3 );
00263 }
00264 
00265 void ProbeDialog::timeout()
00266 {
00267     disconnectDevices();
00268     if (!fDetected) {
00269         fStatusLabel->setText( i18n("Timeout reached, could not detect a handheld.") );
00270         KMessageBox::information ( this
00271             , i18n("<qt>"
00272                 "<p>A handheld could not be detected. Possible check the following "
00273                 "things:</p>"
00274                 "<ul>"
00275                 "<li>Have you pressed the hotsync button on the handheld?</li>"
00276                 "<li>Make sure the device sits in the cradle correctly.</li>"
00277                 "<li>Make sure the cradle is correctly plugged in to the computer.</li>"
00278                 "<li>Have you checked that your device is actually supported by kpilot"
00279                 " (see http://www.kpilot.org).</li>"
00280                 "</ul></qt>"
00281             ), i18n("Automatic Detection Failed"), "AutoDetectionFailed");
00282     }
00283 }
00284 
00285 void ProbeDialog::connection( KPilotLink *lnk)
00286 {
00287     FUNCTIONSETUP;
00288 
00289     fActiveLink = static_cast<KPilotDeviceLink*>(lnk);
00290     if ( !fActiveLink )
00291     {
00292         return;
00293     }
00294     const KPilotUser &usr( fActiveLink->getPilotUser() );
00295 
00296     fUserName = usr.name();
00297     fDeviceName = fActiveLink->pilotPath();
00298 
00299     fStatusLabel->setText( i18n("Found a connected device on %1",fDeviceName) );
00300     fUserNameLabel->setText( fUserName );
00301     fDeviceNameLabel->setText( fDeviceName );
00302     fDetected = true;
00303 
00304     fResultsGroup->setEnabled( true );
00305     enableButtonOk(true);
00306 
00307     QTimer::singleShot(0, this, SLOT(retrieveDBList()));
00308 }
00309 
00310 void ProbeDialog::retrieveDBList()
00311 {
00312     KPilotLink::DBInfoList dbs = fActiveLink->getDBList();
00313     fDBs.clear();
00314     char buff[7];
00315     buff[0] = '[';
00316 
00317     for ( KPilotLink::DBInfoList::ConstIterator i = dbs.begin(); i != dbs.end(); ++i )
00318     {
00319         set_long( &buff[1], (*i).creator );
00320         buff[5] = ']';
00321         buff[6] = '\0';
00322         QString cr( buff );
00323         fDBs << cr;
00324         fDBs << QString( (*i).name );
00325     }
00326     fDBs.sort();
00327 
00328     QString old;
00329     QStringList::Iterator itr = fDBs.begin();
00330     while ( itr != fDBs.end() )
00331     {
00332         if ( old == *itr )
00333         {
00334             itr = fDBs.erase( itr );
00335         }
00336         else
00337         {
00338             old = *itr;
00339             ++itr;
00340         }
00341     }
00342 
00343     // End sync gracefully, but don't change settings on the handheld.
00344     fActiveLink->endSync( KPilotLink::NoUpdate );
00345 
00346     QTimer::singleShot(0, this, SLOT(disconnectDevices()));
00347 }
00348 void ProbeDialog::disconnectDevices()
00349 {
00350     FUNCTIONSETUP;
00351 
00352     if (!fDetected)
00353     {
00354         fStatusLabel->setText( i18n("Disconnected from all devices") );
00355     }
00356     fProcessEventsTimer->stop( );
00357     fTimeoutTimer->stop();
00358     fProgressTimer->stop();
00359     fRotateLinksTimer->stop();
00360     fProgress->setValue(fProgress->maximum());
00361     for (int i=0; i<3; ++i)
00362     {
00363         PilotLinkList::iterator end(fDeviceLinks[i].end());
00364         for (PilotLinkList::iterator it=fDeviceLinks[i].begin(); it!=end; ++it)
00365         {
00366             (*it)->close();
00367             KPILOT_DELETE(*it);
00368         }
00369         fDeviceLinks[i].clear();
00370     }
00371 
00372 
00373         OrgKdeKpilotDaemonInterface *daemonInterface = new OrgKdeKpilotDaemonInterface("org.kde.kpilot.daemon", "/Daemon", QDBusConnection::sessionBus());
00374     if (daemonInterface)
00375     {
00376         daemonInterface->startListening();
00377     }
00378     KPILOT_DELETE(daemonInterface);
00379 }
00380 

kpilot

Skip menu "kpilot"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal