kitchensync

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., 51 Franklin Street, Fifth Floor,
00020     Boston, MA 02110-1301, USA.
00021 */
00022 
00023 #include <kstandarddirs.h>
00024 #include <kstringhandler.h>
00025 #include <kconfig.h>
00026 #include <klocale.h>
00027 
00028 #include <konnectorinfo.h>
00029 
00030 #include "qtopiaconfig.h"
00031 #include "socket.h"
00032 
00033 #include "qtopiakonnector.h"
00034 
00035 using namespace KSync;
00036 
00037 class QtopiaKonnectorFactory : public KRES::PluginFactoryBase
00038 {
00039   public:
00040     KRES::Resource *resource( const KConfig *config )
00041     {
00042       return new QtopiaKonnector( config );
00043     }
00044 
00045     KRES::ConfigWidget *configWidget( QWidget *parent )
00046     {
00047       return new OpieHelper::QtopiaConfig( parent );
00048     }
00049 };
00050 
00051 extern "C"
00052 {
00053   void *init_libqtopiakonnector()
00054   {
00055     KGlobal::locale()->insertCatalogue( "konnector_qtopia" );
00056     return new QtopiaKonnectorFactory();
00057   }
00058 }
00059 
00060 
00061 class QtopiaKonnector::Private
00062 {
00063   public:
00064     Private()
00065       : socket( 0 )
00066     {
00067     }
00068 
00069     ~Private()
00070     {
00071       delete socket;
00072       socket = 0;
00073     }
00074 
00075     QtopiaSocket *socket;
00076 };
00077 
00078 QtopiaKonnector::QtopiaKonnector( const KConfig *cfg )
00079     : Konnector( cfg )
00080 {
00081   if ( cfg ) {
00082     mDestinationIP = cfg->readEntry( "DestinationIP" );
00083     mUserName = cfg->readEntry( "UserName" );
00084     mPassword = KStringHandler::obscure( cfg->readEntry( "Password" ) );
00085     mModel = cfg->readEntry( "Model" );
00086     mModelName = cfg->readEntry( "ModelName" );
00087   }
00088 
00089   d = new Private;
00090   d->socket = new QtopiaSocket(this, "Opie Socket" );
00091   d->socket->setStoragePath( storagePath() );
00092 
00093   /* now do some signal and slot connection */
00094   connect( this, SIGNAL(storagePathChanged(const QString&)),
00095            d->socket, SLOT(setStoragePath(const QString&)) );
00096   connect( d->socket, SIGNAL( sync( SynceeList ) ),
00097            this, SLOT( slotSync( SynceeList ) ) );
00098 
00099   d->socket->setDestIP( mDestinationIP );
00100   d->socket->setUser( mUserName );
00101   d->socket->setPassword( mPassword );
00102   d->socket->setModel( mModel, mModelName );
00103 }
00104 
00105 QtopiaKonnector::~QtopiaKonnector()
00106 {
00107   delete d;
00108   d = 0;
00109 }
00110 
00111 void QtopiaKonnector::writeConfig( KConfig *cfg )
00112 {
00113   Konnector::writeConfig( cfg );
00114 
00115   cfg->writeEntry( "DestinationIP", mDestinationIP );
00116   cfg->writeEntry( "UserName", mUserName );
00117   cfg->writeEntry( "Password", KStringHandler::obscure( mPassword ) );
00118   cfg->writeEntry( "Model", mModel );
00119   cfg->writeEntry( "ModelName", mModelName );
00120 }
00121 
00122 SynceeList QtopiaKonnector::syncees()
00123 {
00124   return mSynceeList;
00125 }
00126 
00127 bool QtopiaKonnector::readSyncees()
00128 {
00129   d->socket->setResources( resources() );
00130   return d->socket->startSync();
00131 }
00132 
00133 bool QtopiaKonnector::connectDevice()
00134 {
00135   d->socket->startUp();
00136   return true;
00137 }
00138 
00139 bool QtopiaKonnector::disconnectDevice()
00140 {
00141   d->socket->hangUp();
00142   return true;
00143 }
00144 
00145 QIconSet QtopiaKonnector::iconSet() const
00146 {
00147   QPixmap logo;
00148   logo.load( locate( "appdata", "pics/opie.png" ) );
00149   return QIconSet( logo );
00150 }
00151 
00152 QString QtopiaKonnector::iconName() const
00153 {
00154   return QString::fromLatin1("opie.png");
00155 }
00156 
00161 void QtopiaKonnector::appendSyncee( KSync::Syncee* syn)
00162 {
00163   mSynceeList.append( syn );
00164 }
00165 
00166 bool QtopiaKonnector::writeSyncees()
00167 {
00168   d->socket->write( mSynceeList );
00169 
00170   emit synceesWritten( this );
00171 
00172   return true;
00173 }
00174 
00175 /* private slots for communication here */
00176 void QtopiaKonnector::slotSync( SynceeList list )
00177 {
00178   mSynceeList = list;
00179   emit synceesRead( this );
00180 }
00181 
00182 KonnectorInfo QtopiaKonnector::info() const
00183 {
00184   return KonnectorInfo( QString::fromLatin1("Qtopia Konnector"),
00185                         iconSet(),
00186                         iconName(),
00187                         d->socket->isConnected() );
00188 }
00189 
00190 QStringList QtopiaKonnector::supportedFilterTypes() const
00191 {
00192   QStringList types;
00193   types << "addressbook" << "calendar";
00194 
00195   return types;
00196 }
00197 
00198 #include "qtopiakonnector.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys