kaddressbook Library API Documentation

locationconfig.cpp

00001 /*
00002     This file is part of KAddressBook.
00003     Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; if not, write to the Free Software
00017     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 
00019     As a special exception, permission is given to link this program
00020     with any edition of Qt, and distribute the resulting executable,
00021     without including the source code for Qt in the source distribution.
00022 */
00023 
00024 #include <qlabel.h>
00025 #include <qlayout.h>
00026 #include <qpushbutton.h>
00027 #include <qtooltip.h>
00028 
00029 #include <kbuttonbox.h>
00030 #include <kdialog.h>
00031 #include <kglobal.h>
00032 #include <klineedit.h>
00033 #include <klistview.h>
00034 #include <klocale.h>
00035 
00036 #include "core.h"
00037 
00038 #include "locationconfig.h"
00039 
00040 LocationConfigWidget::LocationConfigWidget( KABC::AddressBook *ab, QWidget *parent,
00041                                             const char *name )
00042   : KAB::ConfigureWidget( ab, parent, name )
00043 {
00044   QGridLayout *layout = new QGridLayout( this, 3, 3, KDialog::marginHint(),
00045                                          KDialog::spacingHint() );
00046   layout->setColStretch( 1, 1 );
00047 
00048   mListView = new KListView( this );
00049   mListView->addColumn( i18n( "Name" ) );
00050   mListView->addColumn( i18n( "URL" ) );
00051   mListView->setAllColumnsShowFocus( true );
00052   layout->addMultiCellWidget( mListView, 0, 0, 0, 1 );
00053   connect( mListView, SIGNAL( doubleClicked( QListViewItem *, const QPoint &, int  )), this, SLOT(edit()));
00054   KButtonBox *bbox = new KButtonBox( this, Qt::Vertical );
00055   mAddButton = bbox->addButton( i18n( "Add" ), this, SLOT( add() ) );
00056   mEditButton = bbox->addButton( i18n( "Edit" ), this, SLOT( edit() ) );
00057   mRemoveButton = bbox->addButton( i18n( "Remove" ), this, SLOT( remove() ) );
00058   bbox->layout();
00059   layout->addWidget( bbox, 0, 2 );
00060 
00061   QLabel *label = new QLabel( i18n( "Name:" ), this );
00062   layout->addWidget( label, 1, 0 );
00063 
00064   mNameEdit = new KLineEdit( this );
00065   label->setBuddy( mNameEdit );
00066   layout->addMultiCellWidget( mNameEdit, 1, 1, 1, 2 );
00067 
00068   label = new QLabel( i18n( "URL:" ), this );
00069   layout->addWidget( label, 2, 0 );
00070 
00071   mURLEdit = new KLineEdit( this );
00072   label->setBuddy( mURLEdit );
00073   layout->addMultiCellWidget( mURLEdit, 2, 2, 1, 2 );
00074   QToolTip::add( mURLEdit, i18n( "<ul> <li>%s: Street</li>"
00075                                  "<li>%r: Region</li>"
00076                                  "<li>%l: Location</li>"
00077                                  "<li>%z: Zip Code</li>"
00078                                  "<li>%c: Country ISO Code</li> </ul>" ) );
00079 
00080   resize( 500, 300 );
00081 }
00082 
00083 LocationConfigWidget::~LocationConfigWidget()
00084 {
00085 }
00086 
00087 void LocationConfigWidget::restoreSettings( KConfig *cfg )
00088 {
00089   mListView->clear();
00090 
00091   QStringList items = cfg->readListEntry( "URLs" );
00092   if ( items.count() == 0 ) {
00093     QString uid = QDateTime::currentDateTime().toString();
00094 
00095     // add a default, thanks to map24.de for their friendly support
00096     items.append( "map24" );
00097     cfg->writeEntry( "map24", QString( "http://link2.map24.com/?lid=9cc343ae&"
00098                                        "maptype=CGI&"
00099                                        "lang=%1&"
00100                                        "street0=%s&"
00101                                        "zip0=%z&"
00102                                        "city0=%l&"
00103                                        "country0=%c&"
00104                                        "smid=%2" )
00105                                        .arg( KGlobal::locale()->country() )
00106                                        .arg( uid ) );
00107     cfg->writeEntry( "UID", uid );
00108   }
00109 
00110 
00111   QStringList::Iterator it;
00112   for ( it = items.begin(); it != items.end(); ++it )
00113     new QListViewItem( mListView, *it, cfg->readEntry( *it ) );
00114 }
00115 
00116 void LocationConfigWidget::saveSettings( KConfig *cfg )
00117 {
00118   QString group = cfg->group();
00119   QString uid = cfg->readEntry( "UID",
00120                                 QDateTime::currentDateTime().toString() );
00121   cfg->deleteGroup( group );
00122   cfg->setGroup( group );
00123   cfg->writeEntry( "UID", uid );
00124 
00125   QStringList items;
00126   QListViewItem *item;
00127   for ( item = mListView->firstChild(); item; item = item->itemBelow() ) {
00128     cfg->writeEntry( item->text( 0 ), item->text( 1 ) );
00129     items.append( item->text( 0 ) );
00130   }
00131 
00132   cfg->writeEntry( "URLs", items );
00133 }
00134 
00135 void LocationConfigWidget::add()
00136 {
00137   new QListViewItem( mListView, mNameEdit->text(), mURLEdit->text() );
00138 }
00139 
00140 void LocationConfigWidget::remove()
00141 {
00142   QListViewItem *item = mListView->currentItem();
00143   mListView->takeItem( item );
00144   delete item;
00145 }
00146 
00147 void LocationConfigWidget::edit()
00148 {
00149   QListViewItem *item = mListView->currentItem();
00150   if ( !item )
00151     return;
00152 
00153   mNameEdit->setText( item->text( 0 ) );
00154   mURLEdit->setText( item->text( 1 ) );
00155 }
00156 
00157 void LocationConfigWidget::selectionChanged( QListViewItem *item )
00158 {
00159   bool state = ( item != 0 );
00160 
00161   mEditButton->setEnabled( state );
00162   mRemoveButton->setEnabled( state );
00163 }
00164 
00165 void LocationConfigWidget::inputChanged( const QString &text )
00166 {
00167   mAddButton->setEnabled( !text.isEmpty() );
00168 }
00169 
00170 #include "locationconfig.moc"
KDE Logo
This file is part of the documentation for kaddressbook Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat May 1 11:38:52 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003