kitchensync Library API Documentation

qtopiakonnector.cpp

00001 /* 00002 This file is part of KitchenSync. 00003 00004 Copyright (c) 2002,2003 Holger Freyther <freyther@kde.org> 00005 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Library General Public 00009 License as published by the Free Software Foundation; either 00010 version 2 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Library General Public License for more details. 00016 00017 You should have received a copy of the GNU Library General Public License 00018 along with this library; see the file COPYING.LIB. If not, write to 00019 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00020 Boston, MA 02111-1307, USA. 00021 */ 00022 00023 #include <kdebug.h> 00024 #include <kstandarddirs.h> 00025 #include <kconfig.h> 00026 #include <kstringhandler.h> 00027 00028 #include <konnectorinfo.h> 00029 #include <kapabilities.h> 00030 00031 #include "qtopiaconfig.h" 00032 #include "socket.h" 00033 00034 #include "qtopiakonnector.h" 00035 00036 using namespace KSync; 00037 00038 class QtopiaKonnectorFactory : public KRES::PluginFactoryBase 00039 { 00040 public: 00041 KRES::Resource *resource( const KConfig *config ) 00042 { 00043 return new QtopiaKonnector( config ); 00044 } 00045 00046 KRES::ConfigWidget *configWidget( QWidget *parent ) 00047 { 00048 return new OpieHelper::QtopiaConfig( parent ); 00049 } 00050 }; 00051 00052 extern "C" 00053 { 00054 void *init_libqtopiakonnector() 00055 { 00056 return new QtopiaKonnectorFactory(); 00057 } 00058 } 00059 00060 00061 class QtopiaKonnector::Private 00062 { 00063 public: 00064 Private() : socket( 0 ) {} 00065 00066 QtopiaSocket *socket; 00067 }; 00068 00069 QtopiaKonnector::QtopiaKonnector( const KConfig *cfg ) 00070 : Konnector( cfg ) 00071 { 00072 if ( cfg ) { 00073 mDestinationIP = cfg->readEntry( "DestinationIP" ); 00074 mUserName = cfg->readEntry( "UserName" ); 00075 mPassword = KStringHandler::obscure( cfg->readEntry( "Password" ) ); 00076 mModel = cfg->readEntry( "Model" ); 00077 mModelName = cfg->readEntry( "ModelName" ); 00078 } 00079 00080 d = new Private; 00081 d->socket = new QtopiaSocket(this, "Opie Socket" ); 00082 00083 /* now do some signal and slot connection */ 00084 connect( d->socket, SIGNAL( sync( SynceeList ) ), 00085 SLOT( slotSync( SynceeList ) ) ); 00086 connect( d->socket, SIGNAL( error( const Error & ) ), 00087 SLOT( slotError( const Error & ) ) ); 00088 connect( d->socket, SIGNAL( prog( const Progress & ) ), 00089 SLOT( slotProg( const Progress & ) ) ); 00090 00091 d->socket->setDestIP( mDestinationIP ); 00092 d->socket->setUser( mUserName ); 00093 d->socket->setPassword( mPassword ); 00094 d->socket->setModel( mModel, mModelName ); 00095 00096 d->socket->startUp(); 00097 } 00098 00099 QtopiaKonnector::~QtopiaKonnector() 00100 { 00101 delete d; 00102 } 00103 00104 void QtopiaKonnector::writeConfig( KConfig *cfg ) 00105 { 00106 Konnector::writeConfig( cfg ); 00107 00108 cfg->writeEntry( "DestinationIP", mDestinationIP ); 00109 cfg->writeEntry( "UserName", mUserName ); 00110 cfg->writeEntry( "Password", KStringHandler::obscure( mPassword ) ); 00111 cfg->writeEntry( "Model", mModel ); 00112 cfg->writeEntry( "ModelName", mModelName ); 00113 } 00114 00115 Kapabilities QtopiaKonnector::capabilities() 00116 { 00117 Kapabilities caps; 00118 caps.setSupportMetaSyncing( true ); 00119 caps.setSupportsPushSync( true ); 00120 caps.setNeedsConnection( true ); 00121 caps.setSupportsListDir( true ); 00122 caps.setNeedsIPs( true ); 00123 caps.setNeedsSrcIP( false ); 00124 caps.setNeedsDestIP( true ); 00125 caps.setAutoHandle( false ); 00126 caps.setNeedAuthentication( true ); 00127 00128 QValueList<QPair<QString, QString> > user; 00129 user.append(qMakePair(QString::fromLatin1("root"), QString::fromLatin1("rootme") ) ); 00130 caps.setUserProposals( user ); 00131 00132 QStringList ips; 00133 ips << "1.1.1.1"; 00134 caps.setIpProposals( ips ); 00135 00136 // Model Stuff 00137 QStringList models; 00138 models << "Opie and Qtopia 1.6" << "Sharp Zaurus ROM"; 00139 caps.setModels( models ); 00140 caps.setNeedsModelName( true ); 00141 00142 return caps; 00143 } 00144 00145 SynceeList QtopiaKonnector::syncees() 00146 { 00147 return mSynceeList; 00148 } 00149 00150 bool QtopiaKonnector::readSyncees() 00151 { 00152 d->socket->setResources( resources() ); 00153 return d->socket->startSync(); 00154 } 00155 00156 bool QtopiaKonnector::connectDevice() 00157 { 00158 d->socket->startUp(); 00159 return true; 00160 } 00161 00162 bool QtopiaKonnector::disconnectDevice() 00163 { 00164 d->socket->hangUP(); 00165 return true; 00166 } 00167 00168 QString QtopiaKonnector::metaId() const 00169 { 00170 return d->socket->metaId(); 00171 } 00172 00173 QIconSet QtopiaKonnector::iconSet() const 00174 { 00175 kdDebug(5225) << "iconSet" << endl; 00176 QPixmap logo; 00177 logo.load( locate( "appdata", "pics/opie.png" ) ); 00178 return QIconSet( logo ); 00179 } 00180 00181 QString QtopiaKonnector::iconName() const 00182 { 00183 return QString::fromLatin1("opie.png"); 00184 } 00185 00186 bool QtopiaKonnector::writeSyncees() 00187 { 00188 kdDebug(5201) << " writing it now " << endl; 00189 d->socket->write( mSynceeList ); 00190 return true; 00191 } 00192 00193 /* private slots for communication here */ 00194 void QtopiaKonnector::slotSync( SynceeList list ) 00195 { 00196 mSynceeList = list; 00197 emit synceesRead( this ); 00198 } 00199 00200 void QtopiaKonnector::slotError( const Error& err ) 00201 { 00202 error( err ); 00203 } 00204 00205 void QtopiaKonnector::slotProg( const Progress& prog ) 00206 { 00207 progress( prog ); 00208 } 00209 00210 KonnectorInfo QtopiaKonnector::info() const 00211 { 00212 return KonnectorInfo( QString::fromLatin1("Qtopia Konnector"), 00213 iconSet(), 00214 QString::fromLatin1("Qtopia1.5"), 00215 metaId(), 00216 iconName(), 00217 d->socket->isConnected() ); 00218 } 00219 00220 #include "qtopiakonnector.moc"
KDE Logo
This file is part of the documentation for kitchensync Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Oct 1 15:18:59 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003