kitchensync Library API Documentation

plugins/agenda/configwidget.cpp

00001 #include <qcombobox.h>
00002 #include <qlabel.h>
00003 #include <qlineedit.h>
00004 
00005 #include <kapplication.h>
00006 #include <klocale.h>
00007 
00008 #include "configwidget.h"
00009 
00010 using namespace Vr3;
00011 
00012 namespace {
00013     void setCurrent( const QString& str, QComboBox* box, bool insert = true ) {
00014         if (str.isEmpty() ) return;
00015         uint b = box->count();
00016         for ( uint i = 0; i < b; i++ ) {
00017             if ( box->text(i) == str ) {
00018                 box->setCurrentItem(i );
00019                 return;
00020             }
00021         }
00022         if (!insert ) return;
00023 
00024         box->insertItem( str );
00025         box->setCurrentItem( b );
00026     }
00027 }
00028 
00029 ConfigWidget::ConfigWidget( const KSync::Kapabilities& cap,
00030                             QWidget* parent, const char* name )
00031     : KSync::ConfigWidget( cap, parent, name ) {
00032     initUI();
00033     setCapabilities( cap );
00034 }
00035 ConfigWidget::ConfigWidget( QWidget* parent, const char* name )
00036     : KSync::ConfigWidget( parent, name ){
00037     initUI();
00038 }
00039 ConfigWidget::~ConfigWidget() {
00040 }
00041 void ConfigWidget::initUI() {
00042     m_lay = new QGridLayout( this, 2, 5 );
00043     m_lay->addColSpacing( 3, 20 );
00044 
00045 
00046     QLabel* label = new QLabel(this);
00047     label->setText("<qt><h1>Agenda Vr3 Konnector</h1></qt>");
00048 
00049     m_lblIP = new QLabel( this );
00050     m_lblIP->setText(i18n("IP Address:") );
00051     m_cmbIP = new QComboBox( this );
00052     m_cmbIP->setEditable(true);
00053 
00054     m_lblName = new QLabel( this );
00055     m_lblName->setText(i18n("Name:") );
00056     m_lneName = new QLineEdit( this );
00057 
00058     m_lay->addMultiCellWidget( label, 0, 0, 0, 2, AlignLeft );
00059 
00060     m_lay->addWidget( m_lblIP, 1, 0 );
00061     m_lay->addWidget( m_cmbIP, 1, 1 );
00062 
00063     m_lay->addWidget( m_lblName, 1, 3 );
00064     m_lay->addWidget( m_lneName, 1, 4 );
00065 }
00066 
00067 KSync::Kapabilities ConfigWidget::capabilities()const {
00068     KSync::Kapabilities caps;
00069 
00070     caps.setSupportMetaSyncing( true ); // we can meta sync
00071     caps.setSupportsPushSync( true ); // we can initialize the sync from here
00072     caps.setNeedsConnection( true ); // we need to have pppd running
00073     caps.setSupportsListDir( true ); // we will support that once there is API for it...
00074     caps.setNeedsIPs( true ); // we need the IP
00075     caps.setNeedsSrcIP( false ); // we do not bind to any address...
00076     caps.setNeedsDestIP( true ); // we need to know where to connect
00077     caps.setAutoHandle( false ); // we currently do not support auto handling
00078     caps.setNeedAuthentication( false ); // HennevL says we do not need that
00079     caps.setNeedsModelName( true ); // we need a name for our meta path!
00080 
00081     caps.setDestIP( m_cmbIP->currentText() );
00082     caps.setModelName( name() );
00083 
00084     return caps;
00085 }
00086 
00087 void ConfigWidget::setCapabilities( const KSync::Kapabilities& caps) {
00088     setCurrent( caps.destIP(), m_cmbIP );
00089     m_lneName->setText( caps.modelName() );
00090     m_lneName->setEnabled( false ); // needed for the Meta dir path!!!
00091 }
00092 
00093 QString ConfigWidget::name()const {
00094     return m_lneName->text().isEmpty() ? "AgendaVr3" + kapp->randomString(5) : m_lneName->text();
00095 }
00096 
00097 
00098 #include "configwidget.moc"
KDE Logo
This file is part of the documentation for kitchensync Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Dec 21 14:23:40 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003