summaryrefslogtreecommitdiffabout
path: root/kaddressbook
Side-by-side diff
Diffstat (limited to 'kaddressbook') (more/less context) (show whitespace changes)
-rw-r--r--kaddressbook/addresseditwidget.cpp622
-rw-r--r--kaddressbook/addresseditwidget.h159
-rw-r--r--kaddressbook/addresseeconfig.cpp94
-rw-r--r--kaddressbook/addresseeconfig.h55
-rw-r--r--kaddressbook/addresseeeditordialog.cpp129
-rw-r--r--kaddressbook/addresseeeditordialog.h62
-rw-r--r--kaddressbook/addresseeeditorwidget.cpp1284
-rw-r--r--kaddressbook/addresseeeditorwidget.h184
-rw-r--r--kaddressbook/addresseeutil.cpp66
-rw-r--r--kaddressbook/addresseeutil.h61
-rw-r--r--kaddressbook/addviewdialog.cpp118
-rw-r--r--kaddressbook/addviewdialog.h73
-rw-r--r--kaddressbook/configurewidget.cpp54
-rw-r--r--kaddressbook/configurewidget.h67
-rw-r--r--kaddressbook/details/detailsviewcontainer.cpp171
-rw-r--r--kaddressbook/details/detailsviewcontainer.h103
-rw-r--r--kaddressbook/details/global.h28
-rw-r--r--kaddressbook/details/look_basic.cpp75
-rw-r--r--kaddressbook/details/look_basic.h134
-rw-r--r--kaddressbook/details/look_details.cpp419
-rw-r--r--kaddressbook/details/look_details.h157
-rw-r--r--kaddressbook/details/look_html.cpp45
-rw-r--r--kaddressbook/details/look_html.h75
-rw-r--r--kaddressbook/emaileditwidget.cpp275
-rw-r--r--kaddressbook/emaileditwidget.h101
-rw-r--r--kaddressbook/extensionmanager.cpp246
-rw-r--r--kaddressbook/extensionmanager.h88
-rw-r--r--kaddressbook/extensionwidget.cpp84
-rw-r--r--kaddressbook/extensionwidget.h119
-rw-r--r--kaddressbook/features/distributionlistwidget.cpp501
-rw-r--r--kaddressbook/features/distributionlistwidget.h143
-rw-r--r--kaddressbook/features/mergewidget.cpp374
-rw-r--r--kaddressbook/features/mergewidget.h87
-rw-r--r--kaddressbook/filter.cpp205
-rw-r--r--kaddressbook/filter.h153
-rw-r--r--kaddressbook/filtereditdialog.cpp302
-rw-r--r--kaddressbook/filtereditdialog.h104
-rw-r--r--kaddressbook/geowidget.cpp629
-rw-r--r--kaddressbook/geowidget.h155
-rw-r--r--kaddressbook/imagewidget.cpp299
-rw-r--r--kaddressbook/imagewidget.h86
-rw-r--r--kaddressbook/incsearchwidget.cpp147
-rw-r--r--kaddressbook/incsearchwidget.h73
-rw-r--r--kaddressbook/jumpbuttonbar.cpp232
-rw-r--r--kaddressbook/jumpbuttonbar.h84
-rw-r--r--kaddressbook/kabcore.cpp1571
-rw-r--r--kaddressbook/kabcore.h421
-rw-r--r--kaddressbook/kabprefs.cpp127
-rw-r--r--kaddressbook/kabprefs.h88
-rw-r--r--kaddressbook/kaddressbook.desktop8
-rw-r--r--kaddressbook/kaddressbook.pro166
-rw-r--r--kaddressbook/kaddressbookE.pro154
-rw-r--r--kaddressbook/kaddressbookmain.cpp293
-rw-r--r--kaddressbook/kaddressbookmain.h126
-rw-r--r--kaddressbook/kaddressbookview.cpp171
-rw-r--r--kaddressbook/kaddressbookview.h295
-rw-r--r--kaddressbook/kcmconfigs/addresseewidget.cpp236
-rw-r--r--kaddressbook/kcmconfigs/addresseewidget.h87
-rw-r--r--kaddressbook/kcmconfigs/extensionconfigdialog.cpp59
-rw-r--r--kaddressbook/kcmconfigs/extensionconfigdialog.h48
-rw-r--r--kaddressbook/kcmconfigs/kabconfigwidget.cpp357
-rw-r--r--kaddressbook/kcmconfigs/kabconfigwidget.h72
-rw-r--r--kaddressbook/kcmconfigs/kcmkabconfig.cpp86
-rw-r--r--kaddressbook/kcmconfigs/kcmkabconfig.h53
-rw-r--r--kaddressbook/keywidget.cpp277
-rw-r--r--kaddressbook/keywidget.h65
-rw-r--r--kaddressbook/mainembedded.cpp208
-rw-r--r--kaddressbook/nameeditdialog.cpp296
-rw-r--r--kaddressbook/nameeditdialog.h90
-rw-r--r--kaddressbook/old_mainwindow.cpp1561
-rw-r--r--kaddressbook/old_mainwindow.h122
-rw-r--r--kaddressbook/phoneeditwidget.cpp532
-rw-r--r--kaddressbook/phoneeditwidget.h147
-rw-r--r--kaddressbook/secrecywidget.cpp70
-rw-r--r--kaddressbook/secrecywidget.h50
-rw-r--r--kaddressbook/typecombo.h193
-rw-r--r--kaddressbook/undo.cpp119
-rw-r--r--kaddressbook/undo.h95
-rw-r--r--kaddressbook/undocmds.cpp240
-rw-r--r--kaddressbook/undocmds.h117
-rw-r--r--kaddressbook/viewconfigurefieldspage.cpp345
-rw-r--r--kaddressbook/viewconfigurefieldspage.h81
-rw-r--r--kaddressbook/viewconfigurefilterpage.cpp137
-rw-r--r--kaddressbook/viewconfigurefilterpage.h63
-rw-r--r--kaddressbook/viewconfigurewidget.cpp159
-rw-r--r--kaddressbook/viewconfigurewidget.h106
-rw-r--r--kaddressbook/viewmanager.cpp685
-rw-r--r--kaddressbook/viewmanager.h152
-rw-r--r--kaddressbook/views/cardview.cpp1719
-rw-r--r--kaddressbook/views/cardview.desktop18
-rw-r--r--kaddressbook/views/cardview.h473
-rw-r--r--kaddressbook/views/colorlistbox.cpp230
-rw-r--r--kaddressbook/views/colorlistbox.h76
-rw-r--r--kaddressbook/views/configurecardviewdialog.cpp364
-rw-r--r--kaddressbook/views/configurecardviewdialog.h117
-rw-r--r--kaddressbook/views/configuretableviewdialog.cpp155
-rw-r--r--kaddressbook/views/configuretableviewdialog.h88
-rw-r--r--kaddressbook/views/contactlistview.cpp340
-rw-r--r--kaddressbook/views/contactlistview.h128
-rw-r--r--kaddressbook/views/kaddressbookcardview.cpp394
-rw-r--r--kaddressbook/views/kaddressbookcardview.h117
-rw-r--r--kaddressbook/views/kaddressbookiconview.cpp378
-rw-r--r--kaddressbook/views/kaddressbookiconview.h130
-rw-r--r--kaddressbook/views/kaddressbooktableview.cpp337
-rw-r--r--kaddressbook/views/kaddressbooktableview.h114
-rw-r--r--kaddressbook/xxport/csv_xxport.cpp187
-rw-r--r--kaddressbook/xxport/csv_xxport.h68
-rw-r--r--kaddressbook/xxport/csvimportdialog.cpp922
-rw-r--r--kaddressbook/xxport/csvimportdialog.h124
-rw-r--r--kaddressbook/xxport/kde2_xxport.cpp116
-rw-r--r--kaddressbook/xxport/kde2_xxport.h62
-rw-r--r--kaddressbook/xxport/vcard_xxport.cpp238
-rw-r--r--kaddressbook/xxport/vcard_xxport.h64
-rw-r--r--kaddressbook/xxportmanager.cpp269
-rw-r--r--kaddressbook/xxportmanager.h79
-rw-r--r--kaddressbook/xxportobject.cpp152
-rw-r--r--kaddressbook/xxportobject.h157
-rw-r--r--kaddressbook/xxportselectdialog.cpp279
-rw-r--r--kaddressbook/xxportselectdialog.h81
119 files changed, 27026 insertions, 0 deletions
diff --git a/kaddressbook/addresseditwidget.cpp b/kaddressbook/addresseditwidget.cpp
new file mode 100644
index 0000000..3dcd592
--- a/dev/null
+++ b/kaddressbook/addresseditwidget.cpp
@@ -0,0 +1,622 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
+ 2003 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include <qbuttongroup.h>
+#include <qcheckbox.h>
+#include <qhbox.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qlistbox.h>
+#include <qlistview.h>
+#include <qpushbutton.h>
+#include <qsignal.h>
+#include <qstring.h>
+#include <qapplication.h>
+
+#ifndef KAB_EMBEDDED
+#include <qtextedit.h>
+#include <kaccelmanager.h>
+#include <kbuttonbox.h>
+#else //KAB_EMBEDDED
+#include <qmultilineedit.h>
+#endif //KAB_EMBEDDED
+
+#include <qtoolbutton.h>
+#include <qtooltip.h>
+
+#include <kapplication.h>
+#include <kcombobox.h>
+#include <kconfig.h>
+#include <kdebug.h>
+#include <kdialog.h>
+#include <kiconloader.h>
+#include <klineedit.h>
+#include <klistview.h>
+#include <klocale.h>
+#include <kglobal.h>
+#include <kmessagebox.h>
+#include <kseparator.h>
+
+#include "addresseditwidget.h"
+
+
+
+AddressEditWidget::AddressEditWidget( QWidget *parent, const char *name )
+ : QWidget( parent, name )
+{
+
+ mConfig = AddresseeConfig::instance();
+ QVBoxLayout *layout = new QVBoxLayout( this );
+ layout->setSpacing( KDialog::spacingHintSmall() );
+ QHBox *b1 = new QHBox( this);
+ //QLabel * label = new QLabel( b1 );
+ //label->setPixmap( KGlobal::iconLoader()->loadIcon( "gohome", KIcon::Desktop, 0 ) );
+
+
+ //label->setAlignment( AlignCenter);
+ layout->addWidget( b1 );
+ mTypeCombo = new AddressTypeCombo( mAddressList, b1 );
+ QPushButton *editButton = new QPushButton( i18n( "&Edit Addresses..." ),
+ b1 );
+ connect( mTypeCombo, SIGNAL( activated( int ) ),
+ SLOT( updateAddressEdit() ) );
+ // layout->addWidget( mTypeCombo );
+
+#ifndef KAB_EMBEDDED
+ mAddressTextEdit = new QTextEdit( this );
+ mAddressTextEdit->setReadOnly( true );
+ mAddressTextEdit->setMinimumHeight( 20 );
+#else //KAB_EMBEDDED
+ mAddressTextEdit = new QMultiLineEdit( this );
+ mAddressTextEdit->setReadOnly( true );
+ mAddressTextEdit->setMinimumHeight( 20 );
+#endif //KAB_EMBEDDED
+
+ layout->addWidget( mAddressTextEdit );
+
+
+ connect( editButton, SIGNAL( clicked() ), SLOT( edit() ) );
+}
+
+AddressEditWidget::~AddressEditWidget()
+{
+
+}
+
+KABC::Address::List AddressEditWidget::addresses()
+{
+ KABC::Address::List retList;
+
+ KABC::Address::List::Iterator it;
+ for ( it = mAddressList.begin(); it != mAddressList.end(); ++it )
+ if ( !(*it).isEmpty() )
+ retList.append( *it );
+
+ return retList;
+}
+
+void AddressEditWidget::setAddresses( const KABC::Addressee &addr,
+ const KABC::Address::List &list )
+{
+ mAddressee = addr;
+
+ mAddressList.clear();
+
+ // Insert types for existing numbers.
+ mTypeCombo->insertTypeList( list );
+
+ QValueList<int> defaultTypes;
+ defaultTypes << KABC::Address::Home;
+ defaultTypes << KABC::Address::Work;
+
+ mConfig->setUid( mAddressee.uid() );
+ QValueList<int> configList = mConfig->noDefaultAddrTypes();
+ QValueList<int>::ConstIterator it;
+ for ( it = configList.begin(); it != configList.end(); ++it )
+ defaultTypes.remove( *it );
+
+ // Insert default types.
+ // Doing this for mPrefCombo is enough because the list is shared by all
+ // combos.
+ for( it = defaultTypes.begin(); it != defaultTypes.end(); ++it ) {
+ if ( !mTypeCombo->hasType( *it ) )
+ mTypeCombo->insertType( list, *it, Address( *it ) );
+ }
+
+ mTypeCombo->updateTypes();
+
+ // find preferred address which will be shown
+ int preferred = KABC::Address::Home; // default if no preferred address set
+ uint i;
+ for (i = 0; i < list.count(); i++)
+ if ( list[i].type() & KABC::Address::Pref ) {
+ preferred = list[i].type();
+ break;
+ }
+
+ mTypeCombo->selectType( preferred );
+
+ updateAddressEdit();
+}
+
+void AddressEditWidget::edit()
+{
+ AddressEditDialog dialog( mAddressList, mTypeCombo->currentItem(), this );
+ if ( dialog.exec() ) {
+ if ( dialog.changed() ) {
+ mAddressList = dialog.addresses();
+
+ bool hasHome = false, hasWork = false;
+ KABC::Address::List::Iterator it;
+ for ( it = mAddressList.begin(); it != mAddressList.end(); ++it ) {
+ if ( (*it).type() == KABC::Address::Home ) {
+ if ( !(*it).isEmpty() )
+ hasHome = true;
+ }
+ if ( (*it).type() == KABC::Address::Work ) {
+ if ( !(*it).isEmpty() )
+ hasWork = true;
+ }
+ }
+
+ mConfig->setUid( mAddressee.uid() );
+ QValueList<int> configList;
+ if ( !hasHome ) {
+ configList << KABC::Address::Home;
+ }
+ if ( !hasWork ) {
+ configList << KABC::Address::Work;
+ }
+ mConfig->setNoDefaultAddrTypes( configList );
+
+ mTypeCombo->updateTypes();
+ updateAddressEdit();
+ emit modified();
+ }
+ }
+}
+
+void AddressEditWidget::updateAddressEdit()
+{
+ KABC::Address::List::Iterator it = mTypeCombo->selectedElement();
+
+ bool block = signalsBlocked();
+ blockSignals( true );
+
+ mAddressTextEdit->setText( "" );
+
+ if ( it != mAddressList.end() ) {
+ KABC::Address a = *it;
+ if ( !a.isEmpty() ) {
+#if KDE_VERSION >= 319
+ if ( a.type() & KABC::Address::Work ) {
+ mAddressTextEdit->setText( a.formattedAddress( mAddressee.realName(),
+ mAddressee.organization() ) );
+ } else {
+ mAddressTextEdit->setText( a.formattedAddress( mAddressee.realName() ) );
+ }
+#else
+ QString text;
+ if ( !a.street().isEmpty() )
+ text += a.street() + "\n";
+
+ if ( !a.postOfficeBox().isEmpty() )
+ text += a.postOfficeBox() + "\n";
+
+ text += a.locality() + QString(" ") + a.region();
+
+ if ( !a.postalCode().isEmpty() )
+ text += QString(", ") + a.postalCode();
+
+ text += "\n";
+
+ if ( !a.country().isEmpty() )
+ text += a.country() + "\n";
+
+ text += a.extended();
+
+ mAddressTextEdit->setText( text );
+#endif
+ }
+ }
+
+ blockSignals( block );
+}
+
+AddressEditDialog::AddressEditDialog( const KABC::Address::List &list,
+ int selected, QWidget *parent,
+ const char *name )
+ : KDialogBase( Plain, i18n( "Edit Address" ), Ok | Cancel, Ok,
+ parent, name, true, true ),
+ mPreviousAddress( 0 )
+{
+ mAddressList = list;
+
+ QWidget *page = plainPage();
+
+ QGridLayout *topLayout = new QGridLayout( page, 8, 2 );
+ topLayout->setSpacing( spacingHintSmall() );
+
+ mTypeCombo = new AddressTypeCombo( mAddressList, page );
+ topLayout->addMultiCellWidget( mTypeCombo, 0, 0, 0, 1 );
+
+ QLabel *label = new QLabel( i18n( "Street:" ), page );
+ label->setAlignment( Qt::AlignTop | Qt::AlignLeft );
+ topLayout->addWidget( label, 1, 0 );
+
+#ifndef KAB_EMBEDDED
+ mStreetTextEdit = new QTextEdit( page );
+#else //KAB_EMBEDDED
+ mStreetTextEdit = new QMultiLineEdit( page );
+//US qDebug("AddressEditDialog::AddressEditDialog has to be changed");
+#endif //KAB_EMBEDDED
+
+ label->setBuddy( mStreetTextEdit );
+ topLayout->addWidget( mStreetTextEdit, 1, 1 );
+
+ label = new QLabel( i18n( "Post office box:" ), page );
+ topLayout->addWidget( label, 2 , 0 );
+ mPOBoxEdit = new KLineEdit( page );
+ label->setBuddy( mPOBoxEdit );
+ topLayout->addWidget( mPOBoxEdit, 2, 1 );
+ int maxwid = QApplication::desktop()->width();
+ maxwid -= (spacingHintSmall()+label->sizeHint().width() );
+ label = new QLabel( i18n( "Locality:" ), page );
+ topLayout->addWidget( label, 3, 0 );
+ mLocalityEdit = new KLineEdit( page );
+ label->setBuddy( mLocalityEdit );
+ topLayout->addWidget( mLocalityEdit, 3, 1 );
+
+ label = new QLabel( i18n( "Region:" ), page );
+ topLayout->addWidget( label, 4, 0 );
+ mRegionEdit = new KLineEdit( page );
+ label->setBuddy( mRegionEdit );
+ topLayout->addWidget( mRegionEdit, 4, 1 );
+
+ label = new QLabel( i18n( "Postal code:" ), page );
+ topLayout->addWidget( label, 5, 0 );
+ mPostalCodeEdit = new KLineEdit( page );
+ label->setBuddy( mPostalCodeEdit );
+ topLayout->addWidget( mPostalCodeEdit, 5, 1 );
+
+ label = new QLabel( i18n( "Country:" ), page );
+ topLayout->addWidget( label, 6, 0 );
+ mCountryCombo = new KComboBox( page );
+
+ mCountryCombo->setMaximumWidth( maxwid -10 );
+ mCountryCombo->setEditable( true );
+ mCountryCombo->setDuplicatesEnabled( false );
+ mCountryCombo->setAutoCompletion( true );
+ fillCountryCombo();
+ label->setBuddy( mCountryCombo );
+ topLayout->addWidget( mCountryCombo, 6, 1 );
+ mCountryCombo->setSizeLimit( 8);
+ mPreferredCheckBox = new QCheckBox( i18n( "This is the preferred address" ), page );
+ topLayout->addMultiCellWidget( mPreferredCheckBox, 7, 7, 0, 1 );
+ /*
+ KSeparator *sep = new KSeparator( KSeparator::HLine, page );
+ topLayout->addMultiCellWidget( sep, 8, 8, 0, 1 );
+ */
+ QHBox *buttonBox = new QHBox( page );
+ buttonBox->setSpacing( spacingHint() );
+ topLayout->addMultiCellWidget( buttonBox, 9, 9, 0, 1 );
+
+ QPushButton *addButton = new QPushButton( i18n( "New..." ), buttonBox );
+ connect( addButton, SIGNAL( clicked() ), SLOT( addAddress() ) );
+
+ mRemoveButton = new QPushButton( i18n( "Remove" ), buttonBox );
+ connect( mRemoveButton, SIGNAL( clicked() ), SLOT( removeAddress() ) );
+
+ mChangeTypeButton = new QPushButton( i18n( "Change Type" ), buttonBox );
+ connect( mChangeTypeButton, SIGNAL( clicked() ), SLOT( changeType() ) );
+
+ mTypeCombo->updateTypes();
+ mTypeCombo->setCurrentItem( selected );
+
+ updateAddressEdits();
+
+ connect( mTypeCombo, SIGNAL( activated( int ) ),
+ SLOT( updateAddressEdits() ) );
+ connect( mStreetTextEdit, SIGNAL( textChanged() ), SLOT( modified() ) );
+ connect( mPOBoxEdit, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) );
+ connect( mLocalityEdit, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) );
+ connect( mRegionEdit, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) );
+ connect( mPostalCodeEdit, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) );
+ connect( mCountryCombo, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) );
+ connect( mPreferredCheckBox, SIGNAL( toggled( bool ) ), SLOT( modified() ) );
+
+#ifndef KAB_EMBEDDED
+ KAcceleratorManager::manage( this );
+#else //KAB_EMBEDDED
+//US qDebug("AddressEditDialog::AddressEditDialog has to be changed 2");
+#endif //KAB_EMBEDDED
+
+ mChanged = false;
+
+ bool state = (mAddressList.count() > 0);
+ mRemoveButton->setEnabled( state );
+ mChangeTypeButton->setEnabled( state );
+#ifndef DESKTOP_VERSION
+ showMaximized();
+#endif
+}
+
+AddressEditDialog::~AddressEditDialog()
+{
+}
+
+KABC::Address::List AddressEditDialog::addresses()
+{
+ saveAddress( *(mTypeCombo->selectedElement()) );
+
+ return mAddressList;
+}
+
+bool AddressEditDialog::changed() const
+{
+ return mChanged;
+}
+
+void AddressEditDialog::addAddress()
+{
+ AddressTypeDialog dlg( mTypeCombo->selectedType(), this );
+ if ( dlg.exec() ) {
+ mAddressList.append( Address( dlg.type() ) );
+
+ mTypeCombo->updateTypes();
+ mTypeCombo->setCurrentItem( mTypeCombo->count() - 1 );
+ updateAddressEdits();
+
+ modified();
+
+ mRemoveButton->setEnabled( true );
+ mChangeTypeButton->setEnabled( true );
+ }
+}
+
+void AddressEditDialog::removeAddress()
+{
+ if ( mAddressList.count() > 0 ) {
+ KABC::Address::List::Iterator it = mTypeCombo->selectedElement();
+ if ( mPreviousAddress && mPreviousAddress->id() == (*it).id() )
+ mPreviousAddress = 0;
+
+ mAddressList.remove( it );
+ mTypeCombo->updateTypes();
+ updateAddressEdits();
+
+ modified();
+ }
+
+ bool state = ( mAddressList.count() > 0 );
+ mRemoveButton->setEnabled( state );
+ mChangeTypeButton->setEnabled( state );
+}
+
+void AddressEditDialog::changeType()
+{
+ KABC::Address::List::Iterator a = mTypeCombo->selectedElement();
+
+ AddressTypeDialog dlg( (*a).type(), this );
+ if ( dlg.exec() ) {
+ (*a).setType( dlg.type() );
+
+ mTypeCombo->updateTypes();
+
+ modified();
+ }
+}
+
+void AddressEditDialog::updateAddressEdits()
+{
+ if ( mPreviousAddress )
+ saveAddress( *mPreviousAddress );
+
+ KABC::Address::List::Iterator it = mTypeCombo->selectedElement();
+ KABC::Address a = *it;
+ mPreviousAddress = &(*it);
+
+ bool tmp = mChanged;
+
+ mStreetTextEdit->setText( a.street() );
+ mRegionEdit->setText( a.region() );
+ mLocalityEdit->setText( a.locality() );
+ mPostalCodeEdit->setText( a.postalCode() );
+ mPOBoxEdit->setText( a.postOfficeBox() );
+
+#ifndef KAB_EMBEDDED
+ mCountryCombo->setCurrentText( a.country() );
+#else //KAB_EMBEDDED
+ mCountryCombo->setEditText( a.country() );
+//US qDebug("AddressEditDialog::updateAddressEdits has to be changed 1");
+#endif //KAB_EMBEDDED
+
+ mPreferredCheckBox->setChecked( a.type() & KABC::Address::Pref );
+
+ mStreetTextEdit->setFocus();
+
+ mChanged = tmp;
+}
+
+void AddressEditDialog::modified()
+{
+ mChanged = true;
+}
+
+void AddressEditDialog::saveAddress( KABC::Address &addr )
+{
+ addr.setLocality( mLocalityEdit->text() );
+ addr.setRegion( mRegionEdit->text() );
+ addr.setPostalCode( mPostalCodeEdit->text() );
+ addr.setCountry( mCountryCombo->currentText() );
+ addr.setPostOfficeBox( mPOBoxEdit->text() );
+ addr.setStreet( mStreetTextEdit->text() );
+
+
+ if ( mPreferredCheckBox->isChecked() ) {
+ KABC::Address::List::Iterator it;
+ for ( it = mAddressList.begin(); it != mAddressList.end(); ++it )
+ (*it).setType( (*it).type() & ~( KABC::Address::Pref ) );
+
+ addr.setType( addr.type() | KABC::Address::Pref );
+ }
+}
+
+void AddressEditDialog::fillCountryCombo()
+{
+ QString country[] = {
+ i18n( "Afghanistan" ), i18n( "Albania" ), i18n( "Algeria" ),
+ i18n( "American Samoa" ), i18n( "Andorra" ), i18n( "Angola" ),
+ i18n( "Anguilla" ), i18n( "Antarctica" ), i18n( "Antigua and Barbuda" ),
+ i18n( "Argentina" ), i18n( "Armenia" ), i18n( "Aruba" ),
+ i18n( "Ashmore and Cartier Islands" ), i18n( "Australia" ),
+ i18n( "Austria" ), i18n( "Azerbaijan" ), i18n( "Bahamas" ),
+ i18n( "Bahrain" ), i18n( "Bangladesh" ), i18n( "Barbados" ),
+ i18n( "Belarus" ), i18n( "Belgium" ), i18n( "Belize" ),
+ i18n( "Benin" ), i18n( "Bermuda" ), i18n( "Bhutan" ),
+ i18n( "Bolivia" ), i18n( "Bosnia and Herzegovina" ), i18n( "Botswana" ),
+ i18n( "Brazil" ), i18n( "Brunei" ), i18n( "Bulgaria" ),
+ i18n( "Burkina Faso" ), i18n( "Burundi" ), i18n( "Cambodia" ),
+ i18n( "Cameroon" ), i18n( "Canada" ), i18n( "Cape Verde" ),
+ i18n( "Cayman Islands" ), i18n( "Central African Republic" ),
+ i18n( "Chad" ), i18n( "Chile" ), i18n( "China" ), i18n( "Colombia" ),
+ i18n( "Comoros" ), i18n( "Congo" ), i18n( "Congo, Dem. Rep." ),
+ i18n( "Costa Rica" ), i18n( "Croatia" ),
+ i18n( "Cuba" ), i18n( "Cyprus" ), i18n( "Czech Republic" ),
+ i18n( "Denmark" ), i18n( "Djibouti" ),
+ i18n( "Dominica" ), i18n( "Dominican Republic" ), i18n( "Ecuador" ),
+ i18n( "Egypt" ), i18n( "El Salvador" ), i18n( "Equatorial Guinea" ),
+ i18n( "Eritrea" ), i18n( "Estonia" ), i18n( "England" ),
+ i18n( "Ethiopia" ), i18n( "European Union" ), i18n( "Faroe Islands" ),
+ i18n( "Fiji" ), i18n( "Finland" ), i18n( "France" ),
+ i18n( "French Polynesia" ), i18n( "Gabon" ), i18n( "Gambia" ),
+ i18n( "Georgia" ), i18n( "Germany" ), i18n( "Ghana" ),
+ i18n( "Greece" ), i18n( "Greenland" ), i18n( "Grenada" ),
+ i18n( "Guam" ), i18n( "Guatemala" ), i18n( "Guinea" ),
+ i18n( "Guinea-Bissau" ), i18n( "Guyana" ), i18n( "Haiti" ),
+ i18n( "Honduras" ), i18n( "Hong Kong" ), i18n( "Hungary" ),
+ i18n( "Iceland" ), i18n( "India" ), i18n( "Indonesia" ),
+ i18n( "Iran" ), i18n( "Iraq" ), i18n( "Ireland" ),
+ i18n( "Israel" ), i18n( "Italy" ), i18n( "Ivory Coast" ),
+ i18n( "Jamaica" ), i18n( "Japan" ), i18n( "Jordan" ),
+ i18n( "Kazakhstan" ), i18n( "Kenya" ), i18n( "Kiribati" ),
+ i18n( "Korea, North" ), i18n( "Korea, South" ),
+ i18n( "Kuwait" ), i18n( "Kyrgyzstan" ), i18n( "Laos" ),
+ i18n( "Latvia" ), i18n( "Lebanon" ), i18n( "Lesotho" ),
+ i18n( "Liberia" ), i18n( "Libya" ), i18n( "Liechtenstein" ),
+ i18n( "Lithuania" ), i18n( "Luxembourg" ), i18n( "Macau" ),
+ i18n( "Madagascar" ), i18n( "Malawi" ), i18n( "Malaysia" ),
+ i18n( "Maldives" ), i18n( "Mali" ), i18n( "Malta" ),
+ i18n( "Marshall Islands" ), i18n( "Martinique" ), i18n( "Mauritania" ),
+ i18n( "Mauritius" ), i18n( "Mexico" ),
+ i18n( "Micronesia, Federated States Of" ), i18n( "Moldova" ),
+ i18n( "Monaco" ), i18n( "Mongolia" ), i18n( "Montserrat" ),
+ i18n( "Morocco" ), i18n( "Mozambique" ), i18n( "Myanmar" ),
+ i18n( "Namibia" ),
+ i18n( "Nauru" ), i18n( "Nepal" ), i18n( "Netherlands" ),
+ i18n( "Netherlands Antilles" ), i18n( "New Caledonia" ),
+ i18n( "New Zealand" ), i18n( "Nicaragua" ), i18n( "Niger" ),
+ i18n( "Nigeria" ), i18n( "Niue" ), i18n( "North Korea" ),
+ i18n( "Northern Ireland" ), i18n( "Northern Mariana Islands" ),
+ i18n( "Norway" ), i18n( "Oman" ), i18n( "Pakistan" ), i18n( "Palau" ),
+ i18n( "Palestinian" ), i18n( "Panama" ), i18n( "Papua New Guinea" ),
+ i18n( "Paraguay" ), i18n( "Peru" ), i18n( "Philippines" ),
+ i18n( "Poland" ), i18n( "Portugal" ), i18n( "Puerto Rico" ),
+ i18n( "Qatar" ), i18n( "Romania" ), i18n( "Russia" ), i18n( "Rwanda" ),
+ i18n( "St. Kitts and Nevis" ), i18n( "St. Lucia" ),
+ i18n( "St. Vincent and the Grenadines" ), i18n( "San Marino" ),
+ i18n( "Sao Tome and Principe" ), i18n( "Saudi Arabia" ),
+ i18n( "Senegal" ), i18n( "Serbia & Montenegro" ), i18n( "Seychelles" ),
+ i18n( "Sierra Leone" ), i18n( "Singapore" ), i18n( "Slovakia" ),
+ i18n( "Slovenia" ), i18n( "Solomon Islands" ), i18n( "Somalia" ),
+ i18n( "South Africa" ), i18n( "South Korea" ), i18n( "Spain" ),
+ i18n( "Sri Lanka" ), i18n( "St. Kitts and Nevis" ), i18n( "Sudan" ),
+ i18n( "Suriname" ), i18n( "Swaziland" ), i18n( "Sweden" ),
+ i18n( "Switzerland" ), i18n( "Syria" ), i18n( "Taiwan" ),
+ i18n( "Tajikistan" ), i18n( "Tanzania" ), i18n( "Thailand" ),
+ i18n( "Tibet" ), i18n( "Togo" ), i18n( "Tonga" ),
+ i18n( "Trinidad and Tobago" ), i18n( "Tunisia" ), i18n( "Turkey" ),
+ i18n( "Turkmenistan" ), i18n( "Turks and Caicos Islands" ),
+ i18n( "Tuvalu" ), i18n( "Uganda " ), i18n( "Ukraine" ),
+ i18n( "United Arab Emirates" ), i18n( "United Kingdom" ),
+ i18n( "United States" ), i18n( "Uruguay" ), i18n( "Uzbekistan" ),
+ i18n( "Vanuatu" ), i18n( "Vatican City" ), i18n( "Venezuela" ),
+ i18n( "Vietnam" ), i18n( "Western Samoa" ), i18n( "Yemen" ),
+ i18n( "Yugoslavia" ), i18n( "Zaire" ), i18n( "Zambia" ),
+ i18n( "Zimbabwe" ),
+ ""
+ };
+
+ QStringList countries;
+ for ( int i = 0; !country[ i ].isEmpty(); ++i )
+ countries.append( country[ i ] );
+
+ countries.sort();
+
+ mCountryCombo->insertStringList( countries );
+}
+
+
+AddressTypeDialog::AddressTypeDialog( int type, QWidget *parent )
+ : KDialogBase( Plain, i18n( "Edit Address Type" ), Ok | Cancel, Ok,
+ parent, "AddressTypeDialog" )
+{
+ QWidget *page = plainPage();
+ QVBoxLayout *layout = new QVBoxLayout( page );
+
+ mGroup = new QButtonGroup( 2, Horizontal, i18n( "Address Types" ), page );
+ layout->addWidget( mGroup );
+
+ mTypeList = KABC::Address::typeList();
+ mTypeList.remove( KABC::Address::Pref );
+
+ KABC::Address::TypeList::Iterator it;
+ for ( it = mTypeList.begin(); it != mTypeList.end(); ++it )
+ new QCheckBox( KABC::Address::typeLabel( *it ), mGroup );
+
+ for ( int i = 0; i < mGroup->count(); ++i ) {
+ QCheckBox *box = (QCheckBox*)mGroup->find( i );
+ box->setChecked( type & mTypeList[ i ] );
+ }
+}
+
+AddressTypeDialog::~AddressTypeDialog()
+{
+}
+
+int AddressTypeDialog::type() const
+{
+ int type = 0;
+ for ( int i = 0; i < mGroup->count(); ++i ) {
+ QCheckBox *box = (QCheckBox*)mGroup->find( i );
+ if ( box->isChecked() )
+ type += mTypeList[ i ];
+ }
+
+ return type;
+}
+
+#ifndef KAB_EMBEDDED
+#include "addresseditwidget.moc"
+#endif //KAB_EMBEDDED
diff --git a/kaddressbook/addresseditwidget.h b/kaddressbook/addresseditwidget.h
new file mode 100644
index 0000000..bc96d74
--- a/dev/null
+++ b/kaddressbook/addresseditwidget.h
@@ -0,0 +1,159 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef ADDRESSEDITWIDGET_H
+#define ADDRESSEDITWIDGET_H
+
+#include <qwidget.h>
+
+#include <kdialogbase.h>
+#include <kabc/address.h>
+#include <kabc/addressee.h>
+
+#include "addresseeconfig.h"
+#include "typecombo.h"
+
+class QButtonGroup;
+class QCheckBox;
+class QListView;
+#ifndef KAB_EMBEDDED
+class QTextEdit;
+#else //KAB_EMBEDDED
+class QMultiLineEdit;
+#endif //KAB_EMBEDDED
+class QToolButton;
+
+class KComboBox;
+class KLineEdit;
+class KListView;
+
+typedef TypeCombo<KABC::Address> AddressTypeCombo;
+
+/**
+ Editor widget for addresses.
+ */
+class AddressEditWidget : public QWidget
+{
+ Q_OBJECT
+
+ public:
+ AddressEditWidget( QWidget *parent, const char *name = 0 );
+ ~AddressEditWidget();
+
+ KABC::Address::List addresses();
+ void setAddresses( const KABC::Addressee &addr,
+ const KABC::Address::List &list );
+
+ void updateTypeCombo( const KABC::Address::List&, KComboBox* );
+ KABC::Address currentAddress( KComboBox*, int );
+
+ signals:
+ void modified();
+
+ protected slots:
+ void updateAddressEdit();
+
+ void edit();
+
+ private:
+ AddresseeConfig * mConfig;
+ AddressTypeCombo *mTypeCombo;
+
+ QPushButton *mEditButton;
+#ifndef KAB_EMBEDDED
+ QTextEdit *mAddressTextEdit;
+#else //KAB_EMBEDDED
+ QMultiLineEdit *mAddressTextEdit;
+#endif //KAB_EMBEDDED
+
+ KABC::Address::List mAddressList;
+ KABC::Addressee mAddressee;
+ int mIndex;
+};
+
+/**
+ Dialog for editing address details.
+ */
+class AddressEditDialog : public KDialogBase
+{
+ Q_OBJECT
+
+ public:
+ AddressEditDialog( const KABC::Address::List &list, int selected,
+ QWidget *parent, const char *name = 0 );
+ ~AddressEditDialog();
+
+ KABC::Address::List addresses();
+ bool changed() const;
+
+ protected slots:
+ void addAddress();
+ void removeAddress();
+ void changeType();
+
+ void updateAddressEdits();
+ void modified();
+
+ private:
+ void saveAddress( KABC::Address &addr );
+ void fillCountryCombo();
+
+ AddressTypeCombo *mTypeCombo;
+#ifndef KAB_EMBEDDED
+ QTextEdit *mStreetTextEdit;
+#else //KAB_EMBEDDED
+ QMultiLineEdit *mStreetTextEdit;
+#endif //KAB_EMBEDDED
+ KComboBox *mCountryCombo;
+ KLineEdit *mRegionEdit;
+ KLineEdit *mLocalityEdit;
+ KLineEdit *mPostalCodeEdit;
+ KLineEdit *mPOBoxEdit;
+ QCheckBox *mPreferredCheckBox;
+
+ QPushButton *mRemoveButton;
+ QPushButton *mChangeTypeButton;
+
+ KABC::Address::List mAddressList;
+ KABC::Address *mPreviousAddress;
+ bool mChanged;
+};
+
+/**
+ Dialog for selecting an address type.
+ */
+class AddressTypeDialog : public KDialogBase
+{
+ public:
+ AddressTypeDialog( int type, QWidget *parent );
+ ~AddressTypeDialog();
+
+ int type() const;
+
+ private:
+ QButtonGroup *mGroup;
+
+ KABC::Address::TypeList mTypeList;
+};
+
+#endif
diff --git a/kaddressbook/addresseeconfig.cpp b/kaddressbook/addresseeconfig.cpp
new file mode 100644
index 0000000..ea0436f
--- a/dev/null
+++ b/kaddressbook/addresseeconfig.cpp
@@ -0,0 +1,94 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include "addresseeconfig.h"
+#include "kabprefs.h"
+//US
+#include <kstandarddirs.h>
+#include <qfileinfo.h>
+
+using namespace KABC;
+
+static AddresseeConfig* extern_AddresseeConfig = 0;
+static KConfig * extern_Config = 0;
+
+AddresseeConfig::AddresseeConfig()
+{
+
+
+}
+AddresseeConfig::~AddresseeConfig()
+{
+ delete AddresseeConfig::config();
+}
+
+
+AddresseeConfig* AddresseeConfig::instance()
+{
+ if ( ! extern_AddresseeConfig )
+ extern_AddresseeConfig = new AddresseeConfig();
+ return extern_AddresseeConfig;
+}
+KConfig* AddresseeConfig::config()
+{
+ if ( ! extern_Config ) {
+ QString conf = locateLocal("config", "kaddressrc");
+ extern_Config= new KConfig( conf );
+ }
+ return extern_Config;
+}
+
+
+void AddresseeConfig::setUid( const QString & uid )
+{
+ AddresseeConfig::config()->setGroup( uid );
+ mUid = uid;
+}
+
+void AddresseeConfig::setAutomaticNameParsing( bool value )
+{
+ AddresseeConfig::config()->writeEntry( "AutomaticNameParsing", value );
+}
+
+ bool AddresseeConfig::automaticNameParsing()
+{
+
+ return AddresseeConfig::config()->readBoolEntry( "AutomaticNameParsing",
+ KABPrefs::instance()->mAutomaticNameParsing );
+}
+
+void AddresseeConfig::setNoDefaultAddrTypes( const QValueList<int> &types )
+{
+ AddresseeConfig::config()->writeEntry( "NoDefaultAddrTypes", types );
+ AddresseeConfig::config()->sync();
+}
+
+ QValueList<int> AddresseeConfig::noDefaultAddrTypes() const
+{
+ return AddresseeConfig::config()->readIntListEntry( "NoDefaultAddrTypes" );
+}
+
+void AddresseeConfig::remove( const QString & uid )
+{
+ AddresseeConfig::config()->deleteGroup( uid );
+}
diff --git a/kaddressbook/addresseeconfig.h b/kaddressbook/addresseeconfig.h
new file mode 100644
index 0000000..47fbdd6
--- a/dev/null
+++ b/kaddressbook/addresseeconfig.h
@@ -0,0 +1,55 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef ADDRESSEECONFIG_H
+#define ADDRESSEECONFIG_H
+
+#include <kabc/addressee.h>
+#include <kconfig.h>
+
+using namespace KABC;
+
+class AddresseeConfig
+{
+ public:
+ AddresseeConfig();
+ ~AddresseeConfig();
+ static AddresseeConfig* instance();
+ static KConfig* config();
+
+ Addressee addressee();
+
+ void setUid( const QString & uid );
+ void setAutomaticNameParsing( bool value );
+ bool automaticNameParsing();
+
+ void setNoDefaultAddrTypes( const QValueList<int> &types );
+ QValueList<int> noDefaultAddrTypes() const;
+
+ void remove( const QString & uid);
+
+ private:
+ QString mUid;
+};
+
+#endif
diff --git a/kaddressbook/addresseeeditordialog.cpp b/kaddressbook/addresseeeditordialog.cpp
new file mode 100644
index 0000000..102138e
--- a/dev/null
+++ b/kaddressbook/addresseeeditordialog.cpp
@@ -0,0 +1,129 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include <qlayout.h>
+
+#include <kdebug.h>
+#include <klocale.h>
+#include <kglobal.h>
+
+#include "addresseeeditorwidget.h"
+#include "kabcore.h"
+
+#include "addresseeeditordialog.h"
+
+AddresseeEditorDialog::AddresseeEditorDialog( KABCore *core, QWidget *parent,
+ const char *name )
+ : KDialogBase( KDialogBase::Plain, i18n( "Edit Contact" ),
+ KDialogBase::Ok | KDialogBase::Cancel | KDialogBase::Apply,
+ KDialogBase::Ok, parent, name, false )
+{
+#ifdef KAB_EMBEDDED
+ resize( KMIN(KGlobal::getDesktopWidth()-10, 490), KMIN(KGlobal::getDesktopHeight()-50, 300));
+#endif //KAB_EMBEDDED
+
+ kdDebug(5720) << "AddresseeEditorDialog()" << endl;
+
+ QWidget *page = plainPage();
+
+ QVBoxLayout *layout = new QVBoxLayout( page );
+
+ mEditorWidget = new AddresseeEditorWidget( core, false, page );
+ connect( mEditorWidget, SIGNAL( modified( const KABC::Addressee::List& ) ),
+ SLOT( widgetModified() ) );
+ layout->addWidget( mEditorWidget );
+
+ enableButton( KDialogBase::Apply, false );
+}
+
+AddresseeEditorDialog::~AddresseeEditorDialog()
+{
+ kdDebug(5720) << "~AddresseeEditorDialog()" << endl;
+
+ emit editorDestroyed( mEditorWidget->addressee().uid() );
+}
+
+void AddresseeEditorDialog::setAddressee( const KABC::Addressee &addr )
+{
+ enableButton( KDialogBase::Apply, false );
+
+ mEditorWidget->setAddressee( addr );
+}
+
+KABC::Addressee AddresseeEditorDialog::addressee()
+{
+ return mEditorWidget->addressee();
+}
+
+bool AddresseeEditorDialog::dirty()
+{
+ return mEditorWidget->dirty();
+}
+
+void AddresseeEditorDialog::slotApply()
+{
+ if ( mEditorWidget->dirty() ) {
+ mEditorWidget->save();
+ emit contactModified( mEditorWidget->addressee() );
+ }
+
+ enableButton( KDialogBase::Apply, false );
+
+ KDialogBase::slotApply();
+}
+
+void AddresseeEditorDialog::slotOk()
+{
+ slotApply();
+
+ KDialogBase::slotOk();
+
+ // Destroy this dialog
+#ifndef KAB_EMBEDDED
+ delayedDestruct();
+#else //KAB_EMBEDDED
+ delete this;
+#endif //KAB_EMBEDDED
+}
+
+void AddresseeEditorDialog::widgetModified()
+{
+ enableButton( KDialogBase::Apply, true );
+}
+
+void AddresseeEditorDialog::slotCancel()
+{
+ KDialogBase::slotCancel();
+
+ // Destroy this dialog
+#ifndef KAB_EMBEDDED
+ delayedDestruct();
+#else //KAB_EMBEDDED
+ delete this;
+#endif //KAB_EMBEDDED
+
+}
+
+#ifndef KAB_EMBEDDED
+#include "addresseeeditordialog.moc"
+#endif //KAB_EMBEDDED
diff --git a/kaddressbook/addresseeeditordialog.h b/kaddressbook/addresseeeditordialog.h
new file mode 100644
index 0000000..1a00d3a
--- a/dev/null
+++ b/kaddressbook/addresseeeditordialog.h
@@ -0,0 +1,62 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef ADDRESSEEEDITORDIALOG_H
+#define ADDRESSEEEDITORDIALOG_H
+
+#include <kdialogbase.h>
+
+#include <kabc/addressbook.h>
+
+class AddresseeEditorWidget;
+class QWidget;
+class KABCore;
+
+class AddresseeEditorDialog : public KDialogBase
+{
+ Q_OBJECT
+
+ public:
+ AddresseeEditorDialog( KABCore *core, QWidget *parent, const char *name = 0 );
+ ~AddresseeEditorDialog();
+
+ void setAddressee( const KABC::Addressee& );
+ KABC::Addressee addressee();
+
+ bool dirty();
+
+ signals:
+ void contactModified( const KABC::Addressee& );
+ void editorDestroyed( const QString& );
+
+ protected slots:
+ virtual void slotApply();
+ virtual void slotOk();
+ virtual void slotCancel();
+ void widgetModified();
+
+ private:
+ AddresseeEditorWidget *mEditorWidget;
+};
+
+#endif
diff --git a/kaddressbook/addresseeeditorwidget.cpp b/kaddressbook/addresseeeditorwidget.cpp
new file mode 100644
index 0000000..4365ee5
--- a/dev/null
+++ b/kaddressbook/addresseeeditorwidget.cpp
@@ -0,0 +1,1284 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include <qcheckbox.h>
+#include <qhbox.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qlistbox.h>
+#include <qpushbutton.h>
+#include <qtabwidget.h>
+
+#ifndef KAB_EMBEDDED
+#include <qtextedit.h>
+
+#include <kaccelmanager.h>
+#include "keywidget.h"
+#include "soundwidget.h"
+
+#else //KAB_EMBEDDED
+#include <qmultilineedit.h>
+#endif //KAB_EMBEDDED
+
+
+#include "keywidget.h"
+#include "geowidget.h"
+#include "imagewidget.h"
+#include "nameeditdialog.h"
+#include "phoneeditwidget.h"
+#include "secrecywidget.h"
+
+
+#include <qtoolbutton.h>
+#include <qtooltip.h>
+
+#include <kapplication.h>
+#include <kconfig.h>
+#include <kcombobox.h>
+#include <kdebug.h>
+#include <kdialogbase.h>
+#include <kglobal.h>
+#include <kiconloader.h>
+#include <klineedit.h>
+#include <klocale.h>
+#include <kmessagebox.h>
+#include <kseparator.h>
+#include <ksqueezedtextlabel.h>
+
+#include <libkdepim/categoryeditdialog.h>
+#include <libkdepim/categoryselectdialog.h>
+
+#include <libkdepim/kdateedit.h>
+
+#include "addresseditwidget.h"
+#include "emaileditwidget.h"
+#include "kabcore.h"
+#include "kabprefs.h"
+
+#include "addresseeeditorwidget.h"
+
+
+
+AddresseeEditorWidget::AddresseeEditorWidget( KABCore *core, bool isExtension,
+ QWidget *parent, const char *name )
+ : ExtensionWidget( core, parent, name ), mIsExtension( isExtension ),
+ mBlockSignals( false )
+{
+
+ mAConfig = AddresseeConfig::instance();
+
+ kdDebug(5720) << "AddresseeEditorWidget()" << endl;
+ mFormattedNameType = NameEditDialog::CustomName;
+ initGUI();
+ mCategoryDialog = 0;
+ mCategoryEditDialog = 0;
+
+ // Load the empty addressee as defaults
+ load();
+
+ mDirty = false;
+}
+
+AddresseeEditorWidget::~AddresseeEditorWidget()
+{
+ kdDebug(5720) << "~AddresseeEditorWidget()" << endl;
+}
+
+void AddresseeEditorWidget::contactsSelectionChanged()
+{
+ KABC::Addressee::List list = selectedContacts();
+
+ mAddressee = list[ 0 ];
+ load();
+}
+
+void AddresseeEditorWidget::setAddressee( const KABC::Addressee &addr )
+{
+ mAddressee = addr;
+ load();
+}
+
+const KABC::Addressee &AddresseeEditorWidget::addressee()
+{
+ return mAddressee;
+}
+
+void AddresseeEditorWidget::textChanged( const QString& )
+{
+ emitModified();
+}
+
+void AddresseeEditorWidget::initGUI()
+{
+ QVBoxLayout *layout = new QVBoxLayout( this );
+
+ mTabWidget = new QTabWidget( this );
+ layout->addWidget( mTabWidget );
+
+ setupTab1();
+ setupTab1_1();
+ setupTab2();
+ setupTab2_1();
+ setupTab3();
+ setupTab3_1();
+
+ mNameEdit->setFocus();
+
+ connect( mTabWidget, SIGNAL( currentChanged(QWidget*) ),
+ SLOT( pageChanged(QWidget*) ) );
+}
+
+void AddresseeEditorWidget::setupTab1()
+{
+ // This is the General tab
+ QWidget *tab1 = new QWidget( mTabWidget );
+
+//US QGridLayout *layout = new QGridLayout( tab1, 11, 7 );
+ QGridLayout *layout = new QGridLayout( tab1, 7, 1 );
+ layout->setMargin( KDialogBase::marginHintSmall() );
+ layout->setSpacing( KDialogBase::spacingHintSmall() );
+
+ QLabel *label;
+ KSeparator* bar;
+ QPushButton *button;
+
+ //////////////////////////////////
+ // Upper left group (person info)
+
+ // Person icon
+ /* LR
+ label = new QLabel( tab1 );
+//US ambiguous call. Add one more parameter
+//US label->setPixmap( KGlobal::iconLoader()->loadIcon( "personal", KIcon::Desktop ) );
+ label->setPixmap( KGlobal::iconLoader()->loadIcon( "personal", KIcon::Desktop, 0 ) );
+ layout->addMultiCellWidget( label, 0, 1, 0, 0 );
+ */
+ // First name
+ button = new QPushButton( i18n( "Name..." ), tab1 );
+//US QToolTip::add( button, i18n( "Edit the contact's name" ) );
+ mNameEdit = new KLineEdit( tab1, "mNameEdit" );
+ connect( mNameEdit, SIGNAL( textChanged( const QString& ) ),
+ SLOT( nameTextChanged( const QString& ) ) );
+ connect( button, SIGNAL( clicked() ), SLOT( nameButtonClicked() ) );
+
+ mNameLabel = new KSqueezedTextLabel( tab1 );
+ mNameLabel->hide();
+
+ layout->addWidget( button, 0, 0 );
+ layout->addWidget( mNameEdit, 0, 1 );
+ layout->addWidget( mNameLabel, 0, 1 );
+
+ label = new QLabel( i18n( "Role:" ), tab1 );
+ mRoleEdit = new KLineEdit( tab1 );
+ connect( mRoleEdit, SIGNAL( textChanged( const QString& ) ),
+ SLOT( textChanged( const QString& ) ) );
+ label->setBuddy( mRoleEdit );
+ layout->addWidget( label, 1, 0 );
+ layout->addWidget( mRoleEdit, 1, 1 );
+
+ // Organization
+ label = new QLabel( i18n( "Organization:" ), tab1 );
+ mOrgEdit = new KLineEdit( tab1 );
+ label->setBuddy( mOrgEdit );
+ connect( mOrgEdit, SIGNAL( textChanged( const QString& ) ),
+ SLOT( textChanged( const QString& ) ) );
+ layout->addWidget( label, 2, 0 );
+ layout->addWidget( mOrgEdit, 2, 1 );
+
+ // File as (formatted name)
+ label = new QLabel( i18n( "Formatted name:" ), tab1 );
+ mFormattedNameLabel = new KSqueezedTextLabel( tab1 );
+ layout->addWidget( label, 3, 0 );
+ layout->addWidget( mFormattedNameLabel, 3, 1 );
+ /* LR
+ // Left hand separator. This separator doesn't go all the way
+ // across so the dialog still flows from top to bottom
+ bar = new KSeparator( KSeparator::HLine, tab1 );
+ layout->addMultiCellWidget( bar, 4, 4, 0, 2 );
+ */
+ //////////////////////////////////////
+
+ /* LR
+ // Phone numbers (upper right)
+ label = new QLabel( tab1 );
+//US loadIcon call is ambiguous. Add one more parameter
+//US label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop ) );
+ label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop, 0 ) );
+//US layout->addMultiCellWidget( label, 0, 1, 3, 3 );
+ layout->addMultiCellWidget( label, 5, 6, 0, 0 );
+ */
+ mPhoneEditWidget = new PhoneEditWidget( tab1 );
+ connect( mPhoneEditWidget, SIGNAL( modified() ), SLOT( emitModified() ) );
+//US layout->addMultiCellWidget( mPhoneEditWidget, 0, 3, 4, 6 );
+ int iii;
+#ifndef DESKTOP_VERSION
+ iii = 7;
+#else
+ iii = 8;
+#endif
+ layout->addMultiCellWidget( mPhoneEditWidget, 4, iii, 0, 1 );
+ ++iii;
+ /* LR
+ bar = new KSeparator( KSeparator::HLine, tab1 );
+//US layout->addMultiCellWidget( bar, 4, 4, 3, 6 );
+ layout->addMultiCellWidget( bar, 9, 9, 0, 2 );
+ */
+/*US
+ //////////////////////////////////////
+ // Addresses (lower left)
+ label = new QLabel( tab1 );
+//US loadIcon call is ambiguous. Add one more parameter
+//US label->setPixmap( KGlobal::iconLoader()->loadIcon( "gohome", KIcon::Desktop ) );
+ label->setPixmap( KGlobal::iconLoader()->loadIcon( "gohome", KIcon::Desktop, 0 ) );
+ layout->addMultiCellWidget( label, 5, 6, 0, 0 );
+
+ mAddressEditWidget = new AddressEditWidget( tab1 );
+ connect( mAddressEditWidget, SIGNAL( modified() ), SLOT( emitModified() ) );
+ layout->addMultiCellWidget( mAddressEditWidget, 5, 9, 1, 2 );
+
+ //////////////////////////////////////
+ // Email / Web (lower right)
+ label = new QLabel( tab1 );
+//US loadIcon call is ambiguous. Add one more parameter
+//US label->setPixmap( KGlobal::iconLoader()->loadIcon( "email", KIcon::Desktop) );
+ label->setPixmap( KGlobal::iconLoader()->loadIcon( "email", KIcon::Desktop, 0) );
+ layout->addMultiCellWidget( label, 5, 6, 3, 3 );
+
+ mEmailWidget = new EmailEditWidget( tab1 );
+ connect( mEmailWidget, SIGNAL( modified() ), SLOT( emitModified() ) );
+ layout->addMultiCellWidget( mEmailWidget, 5, 6, 4, 6 );
+
+ // add the separator
+ bar = new KSeparator( KSeparator::HLine, tab1 );
+ layout->addMultiCellWidget( bar, 7, 7, 3, 6 );
+
+ label = new QLabel( tab1 );
+//US loadIcon call is ambiguous. Add one more parameter
+//US label->setPixmap( KGlobal::iconLoader()->loadIcon( "homepage", KIcon::Desktop) );
+ label->setPixmap( KGlobal::iconLoader()->loadIcon( "homepage", KIcon::Desktop, 0) );
+ layout->addMultiCellWidget( label, 8, 9, 3, 3 );
+
+ label = new QLabel( i18n( "URL:" ), tab1 );
+ mURLEdit = new KLineEdit( tab1 );
+ connect( mURLEdit, SIGNAL( textChanged( const QString& ) ),
+ SLOT( textChanged( const QString& ) ) );
+ label->setBuddy( mURLEdit );
+ layout->addWidget( label, 8, 4 );
+ layout->addMultiCellWidget( mURLEdit, 8, 8, 5, 6 );
+
+ label = new QLabel( i18n( "&IM address:" ), tab1 );
+ mIMAddressEdit = new KLineEdit( tab1 );
+ connect( mIMAddressEdit, SIGNAL( textChanged( const QString& ) ),
+ SLOT( textChanged( const QString& ) ) );
+ label->setBuddy( mIMAddressEdit );
+ layout->addWidget( label, 9, 4 );
+ layout->addMultiCellWidget( mIMAddressEdit, 9, 9, 5, 6 );
+
+ layout->addColSpacing( 6, 50 );
+
+ bar = new KSeparator( KSeparator::HLine, tab1 );
+ layout->addMultiCellWidget( bar, 10, 10, 0, 6 );
+*/
+ ///////////////////////////////////////
+ QHBox *categoryBox = new QHBox( tab1 );
+ categoryBox->setSpacing( KDialogBase::spacingHint() );
+ categoryBox->setMargin( KDialogBase::marginHintSmall() );
+
+ // Categories
+ button = new QPushButton( i18n( "Categories" ), categoryBox );
+ connect( button, SIGNAL( clicked() ), SLOT( categoryButtonClicked() ) );
+
+ mCategoryEdit = new KLineEdit( categoryBox );
+ mCategoryEdit->setReadOnly( true );
+ connect( mCategoryEdit, SIGNAL( textChanged( const QString& ) ),
+ SLOT( textChanged( const QString& ) ) );
+
+ mSecrecyWidget = new SecrecyWidget( categoryBox );
+ connect( mSecrecyWidget, SIGNAL( changed() ), SLOT( emitModified() ) );
+
+//US layout->addMultiCellWidget( categoryBox, 11, 11, 0, 6 );
+ layout->addMultiCellWidget( categoryBox, iii, iii, 0, 1 );
+
+ // Build the layout and add to the tab widget
+ layout->activate(); // required
+
+ mTabWidget->addTab( tab1, i18n( "&General" ) );
+}
+
+
+void AddresseeEditorWidget::setupTab1_1()
+{
+ // This is the Address tab
+ QWidget *tab1_1 = new QWidget( mTabWidget );
+
+//US QGridLayout *layout = new QGridLayout( tab1_1, 11, 7 );
+ QGridLayout *layout = new QGridLayout( tab1_1, 7, 2 );
+ layout->setMargin( KDialogBase::marginHintSmall() );
+ layout->setSpacing( KDialogBase::spacingHintSmall() );
+
+ QLabel *label;
+ KSeparator* bar;
+ QPushButton *button;
+
+/*US
+ //////////////////////////////////
+ // Upper left group (person info)
+
+ // Person icon
+ label = new QLabel( tab1 );
+//US ambiguous call. Add one more parameter
+//US label->setPixmap( KGlobal::iconLoader()->loadIcon( "personal", KIcon::Desktop ) );
+ label->setPixmap( KGlobal::iconLoader()->loadIcon( "personal", KIcon::Desktop, 0 ) );
+ layout->addMultiCellWidget( label, 0, 1, 0, 0 );
+
+ // First name
+ button = new QPushButton( i18n( "Name..." ), tab1 );
+ QToolTip::add( button, i18n( "Edit the contact's name" ) );
+ mNameEdit = new KLineEdit( tab1, "mNameEdit" );
+ connect( mNameEdit, SIGNAL( textChanged( const QString& ) ),
+ SLOT( nameTextChanged( const QString& ) ) );
+ connect( button, SIGNAL( clicked() ), SLOT( nameButtonClicked() ) );
+
+#ifndef KAB_EMBEDDED
+ mNameLabel = new KSqueezedTextLabel( tab1 );
+ mNameLabel->hide();
+#else //KAB_EMBEDDED
+qDebug("AddresseeEditorWidget::setupTab1 has to be changed");
+#endif //KAB_EMBEDDED
+
+ layout->addWidget( button, 0, 1 );
+ layout->addWidget( mNameEdit, 0, 2 );
+
+#ifndef KAB_EMBEDDED
+ layout->addWidget( mNameLabel, 0, 2 );
+#else //KAB_EMBEDDED
+qDebug("AddresseeEditorWidget::setupTab1 has to be changed");
+#endif //KAB_EMBEDDED
+
+ label = new QLabel( i18n( "Role:" ), tab1 );
+ mRoleEdit = new KLineEdit( tab1 );
+ connect( mRoleEdit, SIGNAL( textChanged( const QString& ) ),
+ SLOT( textChanged( const QString& ) ) );
+ label->setBuddy( mRoleEdit );
+ layout->addWidget( label, 1, 1 );
+ layout->addWidget( mRoleEdit, 1, 2 );
+
+ // Organization
+ label = new QLabel( i18n( "Organization:" ), tab1 );
+ mOrgEdit = new KLineEdit( tab1 );
+ label->setBuddy( mOrgEdit );
+ connect( mOrgEdit, SIGNAL( textChanged( const QString& ) ),
+ SLOT( textChanged( const QString& ) ) );
+ layout->addWidget( label, 2, 1 );
+ layout->addWidget( mOrgEdit, 2, 2 );
+
+ // File as (formatted name)
+ label = new QLabel( i18n( "Formatted name:" ), tab1 );
+#ifndef KAB_EMBEDDED
+ mFormattedNameLabel = new KSqueezedTextLabel( tab1 );
+#else //KAB_EMBEDDED
+qDebug("AddresseeEditorWidget::setupTab1 has to be changed");
+#endif //KAB_EMBEDDED
+ layout->addWidget( label, 3, 1 );
+#ifndef KAB_EMBEDDED
+ layout->addWidget( mFormattedNameLabel, 3, 2 );
+#else //KAB_EMBEDDED
+qDebug("AddresseeEditorWidget::setupTab1 has to be changed");
+#endif //KAB_EMBEDDED
+
+ // Left hand separator. This separator doesn't go all the way
+ // across so the dialog still flows from top to bottom
+ bar = new KSeparator( KSeparator::HLine, tab1 );
+ layout->addMultiCellWidget( bar, 4, 4, 0, 2 );
+
+ //////////////////////////////////////
+ // Phone numbers (upper right)
+ label = new QLabel( tab1 );
+//US loadIcon call is ambiguous. Add one more parameter
+//US label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop ) );
+ label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop, 0 ) );
+ layout->addMultiCellWidget( label, 0, 1, 3, 3 );
+
+ mPhoneEditWidget = new PhoneEditWidget( tab1 );
+ connect( mPhoneEditWidget, SIGNAL( modified() ), SLOT( emitModified() ) );
+ layout->addMultiCellWidget( mPhoneEditWidget, 0, 3, 4, 6 );
+
+ bar = new KSeparator( KSeparator::HLine, tab1 );
+ layout->addMultiCellWidget( bar, 4, 4, 3, 6 );
+*/
+ //////////////////////////////////////
+ // Addresses (lower left)
+ /* LR
+ label = new QLabel( tab1_1 );
+//US loadIcon call is ambiguous. Add one more parameter
+//US label->setPixmap( KGlobal::iconLoader()->loadIcon( "gohome", KIcon::Desktop ) );
+ label->setPixmap( KGlobal::iconLoader()->loadIcon( "gohome", KIcon::Desktop, 0 ) );
+//US layout->addMultiCellWidget( label, 5, 6, 0, 0 );
+ layout->addMultiCellWidget( label, 0, 1, 0, 0 );
+ */
+
+ mAddressEditWidget = new AddressEditWidget( tab1_1 );
+ connect( mAddressEditWidget, SIGNAL( modified() ), SLOT( emitModified() ) );
+//US layout->addMultiCellWidget( mAddressEditWidget, 5, 9, 1, 2 );
+ layout->addMultiCellWidget( mAddressEditWidget, 0, 4, 0, 1 );
+
+//US
+/* LR
+ bar = new KSeparator( KSeparator::HLine, tab1_1 );
+ layout->addMultiCellWidget( bar, 5, 5, 0, 3 );
+*/
+
+ //////////////////////////////////////
+ // Email / Web (lower right)
+ /* LR
+ label = new QLabel( tab1_1 );
+//US loadIcon call is ambiguous. Add one more parameter
+//US label->setPixmap( KGlobal::iconLoader()->loadIcon( "email", KIcon::Desktop) );
+ label->setPixmap( KGlobal::iconLoader()->loadIcon( "email", KIcon::Desktop, 0) );
+//US layout->addMultiCellWidget( label, 5, 6, 3, 3 );
+ layout->addMultiCellWidget( label, 6, 7, 0, 0 );
+ */
+ mEmailWidget = new EmailEditWidget( tab1_1 );
+ connect( mEmailWidget, SIGNAL( modified() ), SLOT( emitModified() ) );
+//US layout->addMultiCellWidget( mEmailWidget, 5, 6, 4, 6 );
+ layout->addMultiCellWidget( mEmailWidget, 5, 6, 0, 1 );
+
+ /* LR
+ // add the separator
+ bar = new KSeparator( KSeparator::HLine, tab1_1 );
+//US layout->addMultiCellWidget( bar, 7, 7, 3, 6 );
+ layout->addMultiCellWidget( bar, 8, 8, 0, 3 );
+
+ label = new QLabel( tab1_1 );
+//US loadIcon call is ambiguous. Add one more parameter
+//US label->setPixmap( KGlobal::iconLoader()->loadIcon( "homepage", KIcon::Desktop) );
+ label->setPixmap( KGlobal::iconLoader()->loadIcon( "homepage", KIcon::Desktop, 0) );
+//US layout->addMultiCellWidget( label, 8, 9, 3, 3 );
+ layout->addMultiCellWidget( label, 9, 10, 0, 0 );
+ */
+ label = new QLabel( i18n( "URL:" ), tab1_1 );
+ mURLEdit = new KLineEdit( tab1_1 );
+ connect( mURLEdit, SIGNAL( textChanged( const QString& ) ),
+ SLOT( textChanged( const QString& ) ) );
+ label->setBuddy( mURLEdit );
+//US layout->addWidget( label, 8, 4 );
+ layout->addWidget( label, 7,0 );
+//US layout->addMultiCellWidget( mURLEdit, 8, 8, 5, 6 );
+ layout->addWidget( mURLEdit, 7, 1);
+
+ label = new QLabel( i18n( "&IM address:" ), tab1_1 );
+ mIMAddressEdit = new KLineEdit( tab1_1 );
+ connect( mIMAddressEdit, SIGNAL( textChanged( const QString& ) ),
+ SLOT( textChanged( const QString& ) ) );
+ label->setBuddy( mIMAddressEdit );
+//US layout->addWidget( label, 9, 4 );
+ layout->addWidget( label, 8, 0 );
+//US layout->addMultiCellWidget( mIMAddressEdit, 9, 9, 5, 6 );
+ layout->addWidget( mIMAddressEdit, 8,1 );
+
+//US layout->addColSpacing( 6, 50 );
+
+//US bar = new KSeparator( KSeparator::HLine, tab1_1 );
+//US layout->addMultiCellWidget( bar, 10, 10, 0, 6 );
+
+/*US
+ ///////////////////////////////////////
+ QHBox *categoryBox = new QHBox( tab1 );
+ categoryBox->setSpacing( KDialogBase::spacingHintSmall() );
+
+ // Categories
+ button = new QPushButton( i18n( "Categories" ), categoryBox );
+ connect( button, SIGNAL( clicked() ), SLOT( categoryButtonClicked() ) );
+
+ mCategoryEdit = new KLineEdit( categoryBox );
+ mCategoryEdit->setReadOnly( true );
+ connect( mCategoryEdit, SIGNAL( textChanged( const QString& ) ),
+ SLOT( textChanged( const QString& ) ) );
+
+ mSecrecyWidget = new SecrecyWidget( categoryBox );
+ connect( mSecrecyWidget, SIGNAL( changed() ), SLOT( emitModified() ) );
+
+ layout->addMultiCellWidget( categoryBox, 11, 11, 0, 6 );
+*/
+ // Build the layout and add to the tab widget
+ layout->activate(); // required
+
+ mTabWidget->addTab( tab1_1, i18n( "&Address" ) );
+}
+
+
+
+void AddresseeEditorWidget::setupTab2()
+{
+ // This is the Details tab
+ QWidget *tab2 = new QWidget( mTabWidget );
+
+ QGridLayout *layout = new QGridLayout( tab2, 8, 3 );
+ layout->setMargin( KDialogBase::marginHintSmall() );
+ layout->setSpacing( KDialogBase::spacingHintSmall() );
+
+ QLabel *label;
+ KSeparator* bar;
+
+ ///////////////////////
+ // Office info
+
+ // Department
+ label = new QLabel( tab2 );
+//US loadIcon call is ambiguous. Add one more parameter
+//US label->setPixmap( KGlobal::iconLoader()->loadIcon( "folder", KIcon::Desktop ) );
+ label->setPixmap( KGlobal::iconLoader()->loadIcon( "folder", KIcon::Desktop, 0 ) );
+ layout->addMultiCellWidget( label, 0, 1, 0, 0 );
+
+ label = new QLabel( i18n( "Department:" ), tab2 );
+ layout->addWidget( label, 0, 1 );
+ mDepartmentEdit = new KLineEdit( tab2 );
+ connect( mDepartmentEdit, SIGNAL( textChanged( const QString& ) ),
+ SLOT( textChanged( const QString& ) ) );
+ label->setBuddy( mDepartmentEdit );
+ layout->addWidget( mDepartmentEdit, 0, 2 );
+
+ label = new QLabel( i18n( "Office:" ), tab2 );
+ layout->addWidget( label, 1, 1 );
+ mOfficeEdit = new KLineEdit( tab2 );
+ connect( mOfficeEdit, SIGNAL( textChanged( const QString& ) ),
+ SLOT( textChanged( const QString& ) ) );
+ label->setBuddy( mOfficeEdit );
+ layout->addWidget( mOfficeEdit, 1, 2 );
+
+ label = new QLabel( i18n( "Profession:" ), tab2 );
+ layout->addWidget( label, 2, 1 );
+ mProfessionEdit = new KLineEdit( tab2 );
+ connect( mProfessionEdit, SIGNAL( textChanged( const QString& ) ),
+ SLOT( textChanged( const QString& ) ) );
+ label->setBuddy( mProfessionEdit );
+ layout->addWidget( mProfessionEdit, 2, 2 );
+
+ label = new QLabel( i18n( "Manager\'s name:" ), tab2 );
+//US layout->addWidget( label, 0, 3 );
+ layout->addWidget( label, 3, 1 );
+ mManagerEdit = new KLineEdit( tab2 );
+ connect( mManagerEdit, SIGNAL( textChanged( const QString& ) ),
+ SLOT( textChanged( const QString& ) ) );
+ label->setBuddy( mManagerEdit );
+//US layout->addMultiCellWidget( mManagerEdit, 0, 0, 4, 5 );
+ layout->addWidget( mManagerEdit, 3, 2 );
+
+ label = new QLabel( i18n( "Assistant's name:" ), tab2 );
+//US layout->addWidget( label, 1, 3 );
+ layout->addWidget( label, 4, 1 );
+ mAssistantEdit = new KLineEdit( tab2 );
+ connect( mAssistantEdit, SIGNAL( textChanged( const QString& ) ),
+ SLOT( textChanged( const QString& ) ) );
+ label->setBuddy( mAssistantEdit );
+//US layout->addMultiCellWidget( mAssistantEdit, 1, 1, 4, 5 );
+ layout->addWidget( mAssistantEdit, 4, 2 );
+
+ bar = new KSeparator( KSeparator::HLine, tab2 );
+//US layout->addMultiCellWidget( bar, 3, 3, 0, 5 );
+ layout->addMultiCellWidget( bar, 5, 5, 0, 2 );
+
+ /////////////////////////////////////////////////
+ // Personal info
+
+ label = new QLabel( tab2 );
+//US loadIcon call is ambiguous. Add one more parameter
+//US label->setPixmap( KGlobal::iconLoader()->loadIcon( "personal", KIcon::Desktop ) );
+ label->setPixmap( KGlobal::iconLoader()->loadIcon( "personal", KIcon::Desktop, 0 ) );
+//US layout->addMultiCellWidget( label, 4, 5, 0, 0 );
+ layout->addMultiCellWidget( label, 6, 7, 0, 0 );
+
+ label = new QLabel( i18n( "Nick name:" ), tab2 );
+//US layout->addWidget( label, 4, 1 );
+ layout->addWidget( label, 6, 1 );
+ mNicknameEdit = new KLineEdit( tab2 );
+ connect( mNicknameEdit, SIGNAL( textChanged( const QString& ) ),
+ SLOT( textChanged( const QString& ) ) );
+ label->setBuddy( mNicknameEdit );
+//US layout->addWidget( mNicknameEdit, 4, 2 );
+ layout->addWidget( mNicknameEdit, 6, 2 );
+
+ label = new QLabel( i18n( "Spouse's name:" ), tab2 );
+//US layout->addWidget( label, 5, 1 );
+ layout->addWidget( label, 7, 1 );
+ mSpouseEdit = new KLineEdit( tab2 );
+ connect( mSpouseEdit, SIGNAL( textChanged( const QString& ) ),
+ SLOT( textChanged( const QString& ) ) );
+ label->setBuddy( mSpouseEdit );
+//US layout->addWidget( mSpouseEdit, 5, 2 );
+ layout->addWidget( mSpouseEdit, 7, 2 );
+
+ label = new QLabel( i18n( "Birthday:" ), tab2 );
+//US layout->addWidget( label, 4, 3 );
+ layout->addWidget( label, 8, 1 );
+ mBirthdayPicker = new KDateEdit( tab2 );
+ mBirthdayPicker->setHandleInvalid( true );
+ connect( mBirthdayPicker, SIGNAL( dateChanged( QDate ) ),
+ SLOT( dateChanged( QDate ) ) );
+
+
+#ifndef KAB_EMBEDDED
+ //US invalid dates are handdled by the KDateEdit widget itself
+ connect( mBirthdayPicker, SIGNAL( invalidDateEntered() ),
+ SLOT( invalidDate() ) );
+ connect( mBirthdayPicker, SIGNAL( textChanged( const QString& ) ),
+ SLOT( emitModified() ) );
+#endif //KAB_EMBEDDED
+
+ label->setBuddy( mBirthdayPicker );
+//US layout->addWidget( mBirthdayPicker, 4, 4 );
+ layout->addWidget( mBirthdayPicker, 8, 2 );
+
+ label = new QLabel( i18n( "Anniversary:" ), tab2 );
+//US layout->addWidget( label, 5, 3 );
+ layout->addWidget( label, 9, 1 );
+ mAnniversaryPicker = new KDateEdit( tab2 );
+ mAnniversaryPicker->setHandleInvalid( true );
+ connect( mAnniversaryPicker, SIGNAL( dateChanged( QDate ) ),
+ SLOT( dateChanged( QDate ) ) );
+#ifndef KAB_EMBEDDED
+ //US invalid dates are handled by the KDateEdit widget itself
+ connect( mAnniversaryPicker, SIGNAL( invalidDateEntered() ),
+ SLOT( invalidDate() ) );
+ connect( mAnniversaryPicker, SIGNAL( textChanged( const QString& ) ),
+ SLOT( emitModified() ) );
+#endif //KAB_EMBEDDED
+
+ label->setBuddy( mAnniversaryPicker );
+//US layout->addWidget( mAnniversaryPicker, 5, 4 );
+ layout->addWidget( mAnniversaryPicker, 9, 2 );
+
+/*US
+ bar = new KSeparator( KSeparator::HLine, tab2 );
+ layout->addMultiCellWidget( bar, 6, 6, 0, 5 );
+
+ //////////////////////////////////////
+ // Notes
+ label = new QLabel( i18n( "Note:" ), tab2 );
+ label->setAlignment( Qt::AlignTop | Qt::AlignLeft );
+ layout->addWidget( label, 7, 0 );
+#ifndef KAB_EMBEDDED
+ mNoteEdit = new QTextEdit( tab2 );
+ mNoteEdit->setWordWrap( QTextEdit::WidgetWidth );
+ mNoteEdit->setMinimumSize( mNoteEdit->sizeHint() );
+#else //KAB_EMBEDDED
+ mNoteEdit = new QMultiLineEdit( tab2 );
+//US mNoteEdit->setWordWrap( QTextEdit::WidgetWidth );
+//US mNoteEdit->setMinimumSize( mNoteEdit->sizeHint() );
+qDebug("AddresseeEditorWidget::setupTab2 has to be changed");
+#endif //KAB_EMBEDDED
+ connect( mNoteEdit, SIGNAL( textChanged() ), SLOT( emitModified() ) );
+ label->setBuddy( mNoteEdit );
+ layout->addMultiCellWidget( mNoteEdit, 7, 7, 1, 5 );
+*/
+ // Build the layout and add to the tab widget
+ layout->activate(); // required
+
+ mTabWidget->addTab( tab2, i18n( "&Details" ) );
+}
+
+void AddresseeEditorWidget::setupTab2_1()
+{
+ // This is the Details tab
+ QWidget *tab2_2 = new QWidget( mTabWidget );
+
+ QGridLayout *layout = new QGridLayout( tab2_2, 1, 2 );
+ layout->setMargin( KDialogBase::marginHintSmall() );
+ layout->setSpacing( KDialogBase::spacingHintSmall() );
+
+ QLabel *label;
+ KSeparator* bar;
+
+/*US
+ ///////////////////////
+ // Office info
+
+ // Department
+ label = new QLabel( tab2 );
+//US loadIcon call is ambiguous. Add one more parameter
+//US label->setPixmap( KGlobal::iconLoader()->loadIcon( "folder", KIcon::Desktop ) );
+ label->setPixmap( KGlobal::iconLoader()->loadIcon( "folder", KIcon::Desktop, 0 ) );
+ layout->addMultiCellWidget( label, 0, 1, 0, 0 );
+
+ label = new QLabel( i18n( "Department:" ), tab2 );
+ layout->addWidget( label, 0, 1 );
+ mDepartmentEdit = new KLineEdit( tab2 );
+ connect( mDepartmentEdit, SIGNAL( textChanged( const QString& ) ),
+ SLOT( textChanged( const QString& ) ) );
+ label->setBuddy( mDepartmentEdit );
+ layout->addWidget( mDepartmentEdit, 0, 2 );
+
+ label = new QLabel( i18n( "Office:" ), tab2 );
+ layout->addWidget( label, 1, 1 );
+ mOfficeEdit = new KLineEdit( tab2 );
+ connect( mOfficeEdit, SIGNAL( textChanged( const QString& ) ),
+ SLOT( textChanged( const QString& ) ) );
+ label->setBuddy( mOfficeEdit );
+ layout->addWidget( mOfficeEdit, 1, 2 );
+
+ label = new QLabel( i18n( "Profession:" ), tab2 );
+ layout->addWidget( label, 2, 1 );
+ mProfessionEdit = new KLineEdit( tab2 );
+ connect( mProfessionEdit, SIGNAL( textChanged( const QString& ) ),
+ SLOT( textChanged( const QString& ) ) );
+ label->setBuddy( mProfessionEdit );
+ layout->addWidget( mProfessionEdit, 2, 2 );
+
+ label = new QLabel( i18n( "Manager\'s name:" ), tab2 );
+ layout->addWidget( label, 0, 3 );
+ mManagerEdit = new KLineEdit( tab2 );
+ connect( mManagerEdit, SIGNAL( textChanged( const QString& ) ),
+ SLOT( textChanged( const QString& ) ) );
+ label->setBuddy( mManagerEdit );
+ layout->addMultiCellWidget( mManagerEdit, 0, 0, 4, 5 );
+
+ label = new QLabel( i18n( "Assistant's name:" ), tab2 );
+ layout->addWidget( label, 1, 3 );
+ mAssistantEdit = new KLineEdit( tab2 );
+ connect( mAssistantEdit, SIGNAL( textChanged( const QString& ) ),
+ SLOT( textChanged( const QString& ) ) );
+ label->setBuddy( mAssistantEdit );
+ layout->addMultiCellWidget( mAssistantEdit, 1, 1, 4, 5 );
+
+ bar = new KSeparator( KSeparator::HLine, tab2 );
+ layout->addMultiCellWidget( bar, 3, 3, 0, 5 );
+
+ /////////////////////////////////////////////////
+ // Personal info
+
+ label = new QLabel( tab2 );
+//US loadIcon call is ambiguous. Add one more parameter
+//US label->setPixmap( KGlobal::iconLoader()->loadIcon( "personal", KIcon::Desktop ) );
+ label->setPixmap( KGlobal::iconLoader()->loadIcon( "personal", KIcon::Desktop, 0 ) );
+ layout->addMultiCellWidget( label, 4, 5, 0, 0 );
+
+ label = new QLabel( i18n( "Nick name:" ), tab2 );
+ layout->addWidget( label, 4, 1 );
+ mNicknameEdit = new KLineEdit( tab2 );
+ connect( mNicknameEdit, SIGNAL( textChanged( const QString& ) ),
+ SLOT( textChanged( const QString& ) ) );
+ label->setBuddy( mNicknameEdit );
+ layout->addWidget( mNicknameEdit, 4, 2 );
+
+ label = new QLabel( i18n( "Spouse's name:" ), tab2 );
+ layout->addWidget( label, 5, 1 );
+ mSpouseEdit = new KLineEdit( tab2 );
+ connect( mSpouseEdit, SIGNAL( textChanged( const QString& ) ),
+ SLOT( textChanged( const QString& ) ) );
+ label->setBuddy( mSpouseEdit );
+ layout->addWidget( mSpouseEdit, 5, 2 );
+
+ label = new QLabel( i18n( "Birthday:" ), tab2 );
+ layout->addWidget( label, 4, 3 );
+ mBirthdayPicker = new KDateEdit( tab2 );
+ mBirthdayPicker->setHandleInvalid( true );
+ connect( mBirthdayPicker, SIGNAL( dateChanged( QDate ) ),
+ SLOT( dateChanged( QDate ) ) );
+ connect( mBirthdayPicker, SIGNAL( invalidDateEntered() ),
+ SLOT( invalidDate() ) );
+ connect( mBirthdayPicker, SIGNAL( textChanged( const QString& ) ),
+ SLOT( emitModified() ) );
+ label->setBuddy( mBirthdayPicker );
+ layout->addWidget( mBirthdayPicker, 4, 4 );
+
+ label = new QLabel( i18n( "Anniversary:" ), tab2 );
+ layout->addWidget( label, 5, 3 );
+ mAnniversaryPicker = new KDateEdit( tab2 );
+ mAnniversaryPicker->setHandleInvalid( true );
+ connect( mAnniversaryPicker, SIGNAL( dateChanged( QDate ) ),
+ SLOT( dateChanged( QDate ) ) );
+ connect( mAnniversaryPicker, SIGNAL( invalidDateEntered() ),
+ SLOT( invalidDate() ) );
+ connect( mAnniversaryPicker, SIGNAL( textChanged( const QString& ) ),
+ SLOT( emitModified() ) );
+ label->setBuddy( mAnniversaryPicker );
+ layout->addWidget( mAnniversaryPicker, 5, 4 );
+
+ bar = new KSeparator( KSeparator::HLine, tab2 );
+ layout->addMultiCellWidget( bar, 6, 6, 0, 5 );
+*/
+ //////////////////////////////////////
+ // Notes
+ label = new QLabel( i18n( "Note:" ), tab2_2 );
+ label->setAlignment( Qt::AlignTop | Qt::AlignLeft );
+//US layout->addWidget( label, 7, 0 );
+ layout->addWidget( label, 0, 0 );
+#ifndef KAB_EMBEDDED
+ mNoteEdit = new QTextEdit( tab2_2 );
+ mNoteEdit->setWordWrap( QTextEdit::WidgetWidth );
+ mNoteEdit->setMinimumSize( mNoteEdit->sizeHint() );
+#else //KAB_EMBEDDED
+ mNoteEdit = new QMultiLineEdit( tab2_2 );
+ mNoteEdit->setWordWrap( QMultiLineEdit::WidgetWidth );
+ mNoteEdit->setMinimumSize( mNoteEdit->sizeHint() );
+#endif //KAB_EMBEDDED
+
+ connect( mNoteEdit, SIGNAL( textChanged() ), SLOT( emitModified() ) );
+ label->setBuddy( mNoteEdit );
+//US layout->addMultiCellWidget( mNoteEdit, 7, 7, 1, 5 );
+ layout->addWidget( mNoteEdit, 1, 0);
+
+ // Build the layout and add to the tab widget
+ layout->activate(); // required
+
+ mTabWidget->addTab( tab2_2, i18n( "&Notes" ) );
+}
+
+
+
+void AddresseeEditorWidget::setupTab3()
+{
+ // This is the Misc tab
+ QWidget *tab3 = new QWidget( mTabWidget );
+
+ QGridLayout *layout = new QGridLayout( tab3, 1, 1 );
+ layout->setMargin( KDialogBase::marginHintSmall() );
+ layout->setSpacing( KDialogBase::spacingHintSmall() );
+//US layout->setColStretch( 2, 1 );
+
+ //////////////////////////////////////
+ // Geo
+ mGeoWidget = new GeoWidget( tab3 );
+ // mGeoWidget->setMinimumSize( mGeoWidget->sizeHint() );
+ connect( mGeoWidget, SIGNAL( changed() ), SLOT( emitModified() ) );
+ layout->addWidget( mGeoWidget, 0, 0 );
+/*US
+ //////////////////////////////////////
+ // Sound
+#ifndef KAB_EMBEDDED
+ mSoundWidget = new SoundWidget( tab3 );
+ mSoundWidget->setMinimumSize( mSoundWidget->sizeHint() );
+ connect( mSoundWidget, SIGNAL( changed() ), SLOT( emitModified() ) );
+ layout->addWidget( mSoundWidget, 0, 1, Qt::AlignTop );
+#else //KAB_EMBEDDED
+qDebug("AddresseeEditorWidget::setupTab2 sound part is not supported = has to be changed");
+#endif //KAB_EMBEDDED
+
+ //////////////////////////////////////
+ // Images
+ mImageWidget = new ImageWidget( tab3 );
+ mImageWidget->setMinimumSize( mImageWidget->sizeHint() );
+ connect( mImageWidget, SIGNAL( changed() ), SLOT( emitModified() ) );
+ layout->addWidget( mImageWidget, 1, 0, Qt::AlignTop );
+*/
+//US
+/*
+ KSeparator* bar = new KSeparator( KSeparator::HLine, tab3 );
+ layout->addMultiCellWidget( bar, 1, 1, 0, 0 );
+*/
+ //////////////////////////////////////
+ // Keys
+ mKeyWidget = new KeyWidget( tab3 );
+ //mKeyWidget->setMinimumSize( mKeyWidget->sizeHint() );
+ connect( mKeyWidget, SIGNAL( changed() ), SLOT( emitModified() ) );
+//US layout->addWidget( mKeyWidget, 1, 1, Qt::AlignTop );
+ layout->addWidget( mKeyWidget, 1, 0 );
+
+ mTabWidget->addTab( tab3, i18n( "&Misc" ) );
+}
+
+void AddresseeEditorWidget::setupTab3_1()
+{
+ // This is the Misc tab
+ QWidget *tab3 = new QWidget( mTabWidget );
+
+//US QGridLayout *layout = new QGridLayout( tab3, 2, 3 );
+ QGridLayout *layout = new QGridLayout( tab3, 1, 1 );
+ layout->setMargin( KDialogBase::marginHint() );
+ layout->setSpacing( KDialogBase::spacingHint() );
+//US layout->setColStretch( 2, 1 );
+
+/*US
+ //////////////////////////////////////
+ // Geo
+ mGeoWidget = new GeoWidget( tab3 );
+ mGeoWidget->setMinimumSize( mGeoWidget->sizeHint() );
+ connect( mGeoWidget, SIGNAL( changed() ), SLOT( emitModified() ) );
+ layout->addWidget( mGeoWidget, 0, 0, Qt::AlignTop );
+*/
+ //////////////////////////////////////
+ // Sound
+#ifndef KAB_EMBEDDED
+ mSoundWidget = new SoundWidget( tab3 );
+ mSoundWidget->setMinimumSize( mSoundWidget->sizeHint() );
+ connect( mSoundWidget, SIGNAL( changed() ), SLOT( emitModified() ) );
+ layout->addWidget( mSoundWidget, 0, 1, Qt::AlignTop );
+#else //KAB_EMBEDDED
+//US qDebug("AddresseeEditorWidget::setupTab2 sound part is not supported = has to be changed");
+#endif //KAB_EMBEDDED
+
+ //////////////////////////////////////
+ // Images
+ mImageWidget = new ImageWidget( tab3 );
+ mImageWidget->setMinimumSize( mImageWidget->sizeHint() );
+ connect( mImageWidget, SIGNAL( changed() ), SLOT( emitModified() ) );
+ layout->addWidget( mImageWidget, 0, 0, Qt::AlignTop );
+/*US
+ //////////////////////////////////////
+ // Keys
+ mKeyWidget = new KeyWidget( tab3 );
+ mKeyWidget->setMinimumSize( mKeyWidget->sizeHint() );
+ connect( mKeyWidget, SIGNAL( changed() ), SLOT( emitModified() ) );
+ layout->addWidget( mKeyWidget, 1, 1, Qt::AlignTop );
+*/
+ mTabWidget->addTab( tab3, i18n( "&Images" ) );
+}
+
+
+void AddresseeEditorWidget::load()
+{
+ kdDebug(5720) << "AddresseeEditorWidget::load()" << endl;
+
+ // Block signals in case anything tries to emit modified
+ // CS: This doesn't seem to work.
+ bool block = signalsBlocked();
+ blockSignals( true );
+ mBlockSignals = true; // used for internal signal blocking
+
+ mNameEdit->setText( mAddressee.assembledName() );
+
+ if ( mAddressee.formattedName().isEmpty() ) {
+//US KConfig config( "kaddressbookrc" );
+ KConfig config( locateLocal("config", "kaddressbookrc") );
+ config.setGroup( "General" );
+ mFormattedNameType = config.readNumEntry( "FormattedNameType", 1 );
+ mAddressee.setFormattedName( NameEditDialog::formattedName( mAddressee, mFormattedNameType ) );
+ } else {
+ if ( mAddressee.formattedName() == NameEditDialog::formattedName( mAddressee, NameEditDialog::SimpleName ) )
+ mFormattedNameType = NameEditDialog::SimpleName;
+ else if ( mAddressee.formattedName() == NameEditDialog::formattedName( mAddressee, NameEditDialog::FullName ) )
+ mFormattedNameType = NameEditDialog::FullName;
+ else if ( mAddressee.formattedName() == NameEditDialog::formattedName( mAddressee, NameEditDialog::ReverseName ) )
+ mFormattedNameType = NameEditDialog::ReverseName;
+ else
+ mFormattedNameType = NameEditDialog::CustomName;
+ }
+
+ mFormattedNameLabel->setText( mAddressee.formattedName() );
+
+ mRoleEdit->setText( mAddressee.role() );
+ mOrgEdit->setText( mAddressee.organization() );
+
+//US mURLEdit->setURL( mAddressee.url().url() );
+ mURLEdit->setText( mAddressee.url().prettyURL() );
+//US?? mURLEdit->home( false );
+
+ // mNoteEdit->setText( mAddressee.note() );
+ mNoteEdit->setText( mAddressee.note() );
+ mEmailWidget->setEmails( mAddressee.emails() );
+ mPhoneEditWidget->setPhoneNumbers( mAddressee.phoneNumbers() );
+ mAddressEditWidget->setAddresses( mAddressee, mAddressee.addresses() );
+ mBirthdayPicker->setDate( mAddressee.birthday().date() );
+
+//US mAnniversaryPicker->setDate( QDate::fromString( mAddressee.custom(
+//US "KADDRESSBOOK", "X-Anniversary" ), Qt::ISODate) );
+ QDate dt = KGlobal::locale()->readDate( mAddressee.custom("KADDRESSBOOK", "X-Anniversary" ),
+ "%Y-%m-%d"); // = Qt::ISODate
+ mAnniversaryPicker->setDate( dt );
+
+
+ mNicknameEdit->setText( mAddressee.nickName() );
+ mCategoryEdit->setText( mAddressee.categories().join( "," ) );
+
+ mGeoWidget->setGeo( mAddressee.geo() );
+ mImageWidget->setPhoto( mAddressee.photo() );
+ mImageWidget->setLogo( mAddressee.logo() );
+ mKeyWidget->setKeys( mAddressee.keys() );
+ mSecrecyWidget->setSecrecy( mAddressee.secrecy() );
+#ifndef KAB_EMBEDDED
+ mSoundWidget->setSound( mAddressee.sound() );
+#else //KAB_EMBEDDED
+//US qDebug("AddresseeEditorWidget::load has to be changed 2");
+#endif //KAB_EMBEDDED
+
+ // Load customs
+ mIMAddressEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-IMAddress" ) );
+ mSpouseEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-SpousesName" ) );
+ mManagerEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-ManagersName" ) );
+ mAssistantEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-AssistantsName" ) );
+ mDepartmentEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-Department" ) );
+ mOfficeEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-Office" ) );
+ mProfessionEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-Profession" ) );
+
+ blockSignals( block );
+ mBlockSignals = false;
+
+ mDirty = false;
+}
+
+void AddresseeEditorWidget::save()
+{
+ if ( !mDirty ) return;
+
+ mAddressee.setRole( mRoleEdit->text() );
+ mAddressee.setOrganization( mOrgEdit->text() );
+ mAddressee.setUrl( KURL( mURLEdit->text() ) );
+ mAddressee.setNote( mNoteEdit->text() );
+ if ( mBirthdayPicker->inputIsValid() )
+ mAddressee.setBirthday( QDateTime( mBirthdayPicker->date() ) );
+ else
+ mAddressee.setBirthday( QDateTime() );
+
+ mAddressee.setNickName( mNicknameEdit->text() );
+ mAddressee.setCategories( QStringList::split( ",", mCategoryEdit->text() ) );
+
+ mAddressee.setGeo( mGeoWidget->geo() );
+ mAddressee.setPhoto( mImageWidget->photo() );
+ mAddressee.setLogo( mImageWidget->logo() );
+ mAddressee.setKeys( mKeyWidget->keys() );
+#ifndef KAB_EMBEDDED
+ mAddressee.setSound( mSoundWidget->sound() );
+#else //KAB_EMBEDDED
+//US qDebug("AddresseeEditorWidget::save sound not supported");
+#endif //KAB_EMBEDDED
+ mAddressee.setSecrecy( mSecrecyWidget->secrecy() );
+
+ // save custom fields
+ mAddressee.insertCustom( "KADDRESSBOOK", "X-IMAddress", mIMAddressEdit->text() );
+ mAddressee.insertCustom( "KADDRESSBOOK", "X-SpousesName", mSpouseEdit->text() );
+ mAddressee.insertCustom( "KADDRESSBOOK", "X-ManagersName", mManagerEdit->text() );
+ mAddressee.insertCustom( "KADDRESSBOOK", "X-AssistantsName", mAssistantEdit->text() );
+ mAddressee.insertCustom( "KADDRESSBOOK", "X-Department", mDepartmentEdit->text() );
+ mAddressee.insertCustom( "KADDRESSBOOK", "X-Office", mOfficeEdit->text() );
+ mAddressee.insertCustom( "KADDRESSBOOK", "X-Profession", mProfessionEdit->text() );
+ if ( mAnniversaryPicker->inputIsValid() ) {
+
+//US mAddressee.insertCustom( "KADDRESSBOOK", "X-Anniversary",
+//US mAnniversaryPicker->date().toString( Qt::ISODate ) );
+ int orgformat = KGlobal::locale()->getIntDateFormat();
+ QDate da = mAnniversaryPicker->date();
+ KGlobal::locale()->setIntDateFormat( 2 ); // = Qt::ISODate
+ QString dt = KGlobal::locale()->formatDate(da, true);
+ KGlobal::locale()->setIntDateFormat(orgformat );
+ mAddressee.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt);
+ }
+ else
+ mAddressee.removeCustom( "KADDRESSBOOK", "X-Anniversary" );
+
+ // Save the email addresses
+ QStringList emails = mAddressee.emails();
+ QStringList::Iterator iter;
+ for ( iter = emails.begin(); iter != emails.end(); ++iter )
+ mAddressee.removeEmail( *iter );
+
+ emails = mEmailWidget->emails();
+ bool first = true;
+ for ( iter = emails.begin(); iter != emails.end(); ++iter ) {
+ mAddressee.insertEmail( *iter, first );
+ first = false;
+ }
+
+ // Save the phone numbers
+ KABC::PhoneNumber::List phoneNumbers;
+ KABC::PhoneNumber::List::Iterator phoneIter;
+ phoneNumbers = mAddressee.phoneNumbers();
+ for ( phoneIter = phoneNumbers.begin(); phoneIter != phoneNumbers.end();
+ ++phoneIter )
+ mAddressee.removePhoneNumber( *phoneIter );
+
+ phoneNumbers = mPhoneEditWidget->phoneNumbers();
+ for ( phoneIter = phoneNumbers.begin(); phoneIter != phoneNumbers.end();
+ ++phoneIter )
+ mAddressee.insertPhoneNumber( *phoneIter );
+
+ // Save the addresses
+ KABC::Address::List addresses;
+ KABC::Address::List::Iterator addressIter;
+ addresses = mAddressee.addresses();
+ for ( addressIter = addresses.begin(); addressIter != addresses.end();
+ ++addressIter )
+ mAddressee.removeAddress( *addressIter );
+
+ addresses = mAddressEditWidget->addresses();
+ for ( addressIter = addresses.begin(); addressIter != addresses.end();
+ ++addressIter )
+ mAddressee.insertAddress( *addressIter );
+ mDirty = false;
+}
+
+bool AddresseeEditorWidget::dirty()
+{
+ return mDirty;
+}
+
+void AddresseeEditorWidget::nameTextChanged( const QString &text )
+{
+ // use the addressee class to parse the name for us
+ mAConfig->setUid( mAddressee.uid() );
+ if ( mAConfig->automaticNameParsing() ) {
+ if ( !mAddressee.formattedName().isEmpty() ) {
+ QString fn = mAddressee.formattedName();
+ mAddressee.setNameFromString( text );
+ mAddressee.setFormattedName( fn );
+ } else {
+ // use extra addressee to avoid a formatted name assignment
+ Addressee addr;
+ addr.setNameFromString( text );
+ mAddressee.setPrefix( addr.prefix() );
+ mAddressee.setGivenName( addr.givenName() );
+ mAddressee.setAdditionalName( addr.additionalName() );
+ mAddressee.setFamilyName( addr.familyName() );
+ mAddressee.setSuffix( addr.suffix() );
+ }
+ }
+
+ nameBoxChanged();
+
+ emitModified();
+}
+
+void AddresseeEditorWidget::nameBoxChanged()
+{
+ KABC::Addressee addr;
+ mAConfig->setUid( mAddressee.uid() );
+ if ( mAConfig->automaticNameParsing() ) {
+ addr.setNameFromString( mNameEdit->text() );
+ mNameLabel->hide();
+ mNameEdit->show();
+ } else {
+ addr = mAddressee;
+ mNameEdit->hide();
+ mNameLabel->setText( mNameEdit->text() );
+ mNameLabel->show();
+ }
+
+ if ( mFormattedNameType != NameEditDialog::CustomName ) {
+ mFormattedNameLabel->setText( NameEditDialog::formattedName( mAddressee, mFormattedNameType ) );
+ mAddressee.setFormattedName( NameEditDialog::formattedName( mAddressee, mFormattedNameType ) );
+ }
+}
+
+void AddresseeEditorWidget::nameButtonClicked()
+{
+ // show the name dialog.
+ NameEditDialog dialog( mAddressee, mFormattedNameType, this );
+
+ if ( dialog.exec() ) {
+ if ( dialog.changed() ) {
+ mAddressee.setFamilyName( dialog.familyName() );
+ mAddressee.setGivenName( dialog.givenName() );
+ mAddressee.setPrefix( dialog.prefix() );
+ mAddressee.setSuffix( dialog.suffix() );
+ mAddressee.setAdditionalName( dialog.additionalName() );
+ mFormattedNameType = dialog.formattedNameType();
+ if ( mFormattedNameType == NameEditDialog::CustomName ) {
+ mFormattedNameLabel->setText( dialog.customFormattedName() );
+ mAddressee.setFormattedName( dialog.customFormattedName() );
+ }
+ // Update the name edit.
+ bool block = mNameEdit->signalsBlocked();
+ mNameEdit->blockSignals( true );
+ mNameEdit->setText( mAddressee.assembledName() );
+ mNameEdit->blockSignals( block );
+
+ // Update the combo box.
+ nameBoxChanged();
+
+ emitModified();
+ }
+ }
+}
+
+void AddresseeEditorWidget::categoryButtonClicked()
+{
+ // Show the category dialog
+ if ( mCategoryDialog == 0 ) {
+ mCategoryDialog = new KPIM::CategorySelectDialog( KABPrefs::instance(), this );
+ connect( mCategoryDialog, SIGNAL( categoriesSelected( const QStringList& ) ),
+ SLOT(categoriesSelected( const QStringList& ) ) );
+ connect( mCategoryDialog, SIGNAL( editCategories() ), SLOT( editCategories() ) );
+ }
+
+ mCategoryDialog->setCategories();
+ mCategoryDialog->setSelected( QStringList::split( ",", mCategoryEdit->text() ) );
+ mCategoryDialog->show();
+ mCategoryDialog->raise();
+}
+
+void AddresseeEditorWidget::categoriesSelected( const QStringList &list )
+{
+ mCategoryEdit->setText( list.join( "," ) );
+}
+
+void AddresseeEditorWidget::editCategories()
+{
+ if ( mCategoryEditDialog == 0 ) {
+ mCategoryEditDialog = new KPIM::CategoryEditDialog( KABPrefs::instance(), this );
+ connect( mCategoryEditDialog, SIGNAL( categoryConfigChanged() ),
+ SLOT( categoryButtonClicked() ) );
+ }
+
+ mCategoryEditDialog->show();
+ mCategoryEditDialog->raise();
+}
+
+void AddresseeEditorWidget::emitModified()
+{
+ mDirty = true;
+
+ KABC::Addressee::List list;
+
+ if ( mIsExtension && !mBlockSignals ) {
+ save();
+ list.append( mAddressee );
+ }
+
+ emit modified( list );
+}
+
+void AddresseeEditorWidget::dateChanged( QDate )
+{
+ emitModified();
+}
+
+//US invalid dates are handdled by the KDateEdit widget itself
+void AddresseeEditorWidget::invalidDate()
+{
+ KMessageBox::sorry( this, i18n( "You must specify a valid date" ) );
+}
+
+
+void AddresseeEditorWidget::pageChanged( QWidget *wdg )
+{
+#ifndef KAB_EMBEDDED
+ if ( wdg )
+ KAcceleratorManager::manage( wdg );
+#else //KAB_EMBEDDED
+//US
+#endif //KAB_EMBEDDED
+
+}
+
+QString AddresseeEditorWidget::title() const
+{
+ return i18n( "Contact Editor" );
+}
+
+QString AddresseeEditorWidget::identifier() const
+{
+ return i18n( "contact_editor" );
+}
+
+#ifndef KAB_EMBEDDED
+#include "addresseeeditorwidget.moc"
+#endif //KAB_EMBEDDED
diff --git a/kaddressbook/addresseeeditorwidget.h b/kaddressbook/addresseeeditorwidget.h
new file mode 100644
index 0000000..b9d9e25
--- a/dev/null
+++ b/kaddressbook/addresseeeditorwidget.h
@@ -0,0 +1,184 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef ADDRESSEEEDITORWIDGET_H
+#define ADDRESSEEEDITORWIDGET_H
+
+#include <qdatetime.h>
+
+#include <kabc/addressee.h>
+#include <kdialogbase.h>
+#include <kjanuswidget.h>
+
+#include "extensionwidget.h"
+
+class AddresseeConfig;
+class QCheckBox;
+class QSpinBox;
+class QTabWidget;
+
+#ifndef KAB_EMBEDDED
+class QTextEdit;
+#else //KAB_EMBEDDED
+class QMultiLineEdit;
+#endif //KAB_EMBEDDED
+
+class KComboBox;
+class KDateEdit;
+class KLineEdit;
+class KSqueezedTextLabel;
+
+class AddressEditWidget;
+class EmailEditWidget;
+class GeoWidget;
+class ImageWidget;
+class KABCore;
+class KeyWidget;
+class PhoneEditWidget;
+class SecrecyWidget;
+class SoundWidget;
+
+namespace KPIM
+{
+ class CategorySelectDialog;
+ class CategoryEditDialog;
+}
+
+namespace KABC { class AddressBook; }
+
+class AddresseeEditorWidget : public ExtensionWidget
+{
+ Q_OBJECT
+
+ public:
+ AddresseeEditorWidget( KABCore *core, bool isExtension,
+ QWidget *parent, const char *name = 0 );
+ ~AddresseeEditorWidget();
+
+ void setAddressee( const KABC::Addressee& );
+ const KABC::Addressee &addressee();
+
+ void contactsSelectionChanged();
+
+ void load();
+ void save();
+
+ bool dirty();
+
+ QString title() const;
+ QString identifier() const;
+
+ protected slots:
+ void textChanged( const QString& );
+ void pageChanged( QWidget *wdg );
+
+ /**
+ Emits the modified signal and sets the dirty flag. Any slot
+ that modifies data should use this method instead of calling emit
+ modified() directly.
+ */
+ void emitModified();
+
+ void dateChanged( QDate );
+ void invalidDate();
+ void nameTextChanged( const QString& );
+ void nameBoxChanged();
+ void nameButtonClicked();
+ void categoryButtonClicked();
+
+ /**
+ Called whenever the categories change in the categories dialog.
+ */
+ void categoriesSelected( const QStringList& );
+
+ /**
+ Edits which categories are available in the CategorySelectDialog.
+ */
+ void editCategories();
+
+ private:
+ AddresseeConfig * mAConfig;
+ void initGUI();
+ void setupTab1();
+ void setupTab1_1();
+ void setupTab2();
+ void setupTab2_1();
+ void setupTab3();
+ void setupTab3_1();
+
+ KABC::Addressee mAddressee;
+ int mFormattedNameType;
+ bool mDirty;
+ bool mIsExtension;
+ bool mBlockSignals;
+
+ // GUI
+ KPIM::CategorySelectDialog *mCategoryDialog;
+ KPIM::CategoryEditDialog *mCategoryEditDialog;
+ QTabWidget *mTabWidget;
+
+ // Tab1 and Tab1_1
+ KLineEdit *mNameEdit;
+ KLineEdit *mRoleEdit;
+ KLineEdit *mOrgEdit;
+
+ KSqueezedTextLabel *mFormattedNameLabel;
+ AddressEditWidget *mAddressEditWidget;
+ EmailEditWidget *mEmailWidget;
+ PhoneEditWidget *mPhoneEditWidget;
+ KLineEdit *mURLEdit;
+ KLineEdit *mIMAddressEdit;
+ KLineEdit *mCategoryEdit;
+ SecrecyWidget *mSecrecyWidget;
+ KSqueezedTextLabel *mNameLabel;
+
+ // Tab2 and Tab2_2
+ KLineEdit *mDepartmentEdit;
+ KLineEdit *mOfficeEdit;
+ KLineEdit *mProfessionEdit;
+ KLineEdit *mManagerEdit;
+ KLineEdit *mAssistantEdit;
+ KLineEdit *mNicknameEdit;
+ KLineEdit *mSpouseEdit;
+ KDateEdit *mBirthdayPicker;
+ KDateEdit *mAnniversaryPicker;
+#ifndef KAB_EMBEDDED
+ QTextEdit *mNoteEdit;
+#else //KAB_EMBEDDED
+ QMultiLineEdit *mNoteEdit;
+#endif //KAB_EMBEDDED
+
+ QSpinBox *mTimeZoneSpin;
+ QSpinBox *mGeoLat;
+ QSpinBox *mGeoLon;
+
+ // Tab3
+ GeoWidget *mGeoWidget;
+ ImageWidget *mImageWidget;
+#ifndef KAB_EMBEDDED
+ SoundWidget *mSoundWidget;
+#endif //KAB_EMBEDDED
+ KeyWidget *mKeyWidget;
+};
+
+#endif
diff --git a/kaddressbook/addresseeutil.cpp b/kaddressbook/addresseeutil.cpp
new file mode 100644
index 0000000..366384a
--- a/dev/null
+++ b/kaddressbook/addresseeutil.cpp
@@ -0,0 +1,66 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include <kabc/stdaddressbook.h>
+#include <kabc/vcardconverter.h>
+#include <kdebug.h>
+#include <klocale.h>
+#include <kmessagebox.h>
+
+#include "addresseeutil.h"
+
+QString AddresseeUtil::addresseesToClipboard( const KABC::Addressee::List &list )
+{
+ KABC::VCardConverter converter;
+ QString vcard;
+
+ KABC::Addressee::List::ConstIterator it;
+ for ( it = list.begin(); it != list.end(); ++it ) {
+ QString tmp;
+ if ( converter.addresseeToVCard( *it, tmp ) )
+ vcard += tmp + "\r\n";
+ }
+
+ return vcard;
+}
+
+KABC::Addressee::List AddresseeUtil::clipboardToAddressees( const QString &data )
+{
+ uint numVCards = data.contains( "BEGIN:VCARD", false );
+ QStringList dataList = QStringList::split( "\r\n\r\n", data );
+
+ KABC::Addressee::List addrList;
+ for ( uint i = 0; i < numVCards && i < dataList.count(); ++i ) {
+ KABC::VCardConverter converter;
+ KABC::Addressee addr;
+
+ if ( !converter.vCardToAddressee( dataList[ i ].stripWhiteSpace(), addr ) ) {
+ KMessageBox::error( 0, i18n( "Invalid vCard format in clipboard" ) );
+ continue;
+ }
+
+ addrList.append( addr );
+ }
+
+ return addrList;
+}
diff --git a/kaddressbook/addresseeutil.h b/kaddressbook/addresseeutil.h
new file mode 100644
index 0000000..2eefc1c
--- a/dev/null
+++ b/kaddressbook/addresseeutil.h
@@ -0,0 +1,61 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef ADDRESSEEUTIL_H
+#define ADDRESSEEUTIL_H
+
+#include <qstring.h>
+#include <kabc/addressee.h>
+
+/**
+ This class provides some utility methods for transposing an
+ addressee to different types (ie: clipboard). This class
+ is probably just temporary until these function stablize and move
+ to KABC.
+
+ NOTE: Currently these methods are not implemented properly. The
+ vCard parser in KABC needs to be updated and there is no way to get from
+ KABC::Addressee to vCard.
+*/
+class AddresseeUtil
+{
+ public:
+ /**
+ Same as above function, except that an entire list of KABC::Addressee
+ objects will be converted to vCard and put in the string.
+ */
+ static QString addresseesToClipboard( const KABC::Addressee::List &addrList );
+
+ /**
+ Convert a string from the clipboard into a list of addressee objects.
+ If the clipboard text was not a valid vcard, an empty list
+ will be returned.
+ */
+ static KABC::Addressee::List clipboardToAddressees( const QString &clipboard );
+
+ private:
+ AddresseeUtil() {}
+ ~AddresseeUtil() {}
+};
+
+#endif
diff --git a/kaddressbook/addviewdialog.cpp b/kaddressbook/addviewdialog.cpp
new file mode 100644
index 0000000..6def26b
--- a/dev/null
+++ b/kaddressbook/addviewdialog.cpp
@@ -0,0 +1,118 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef KAB_EMBEDDED
+#endif //KAB_EMBEDDED
+
+#include <qradiobutton.h>
+#include <qbuttongroup.h>
+#include <qlabel.h>
+#include <qlineedit.h>
+#include <qlayout.h>
+
+#include <klocale.h>
+#include <kglobal.h>
+#include "kaddressbookview.h"
+#include "addviewdialog.h"
+
+AddViewDialog::AddViewDialog( QDict<ViewFactory> *viewFactoryDict,
+ QWidget *parent, const char *name )
+ : KDialogBase( KDialogBase::Plain, i18n( "Add View" ),
+ KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok,
+ parent, name ),
+ mViewFactoryDict( viewFactoryDict )
+{
+//US setMinimumSize( KMIN(KGlobal::getDesktopWidth(), 300), KMIN(KGlobal::getDesktopHeight(), 300));
+
+ mTypeId = 0;
+
+ QWidget *page = plainPage();
+
+ QGridLayout *layout = new QGridLayout( page, 2, 2 );
+ layout->setSpacing( spacingHint() );
+ layout->setRowStretch( 1, 1 );
+ layout->setColStretch( 1, 1 );
+
+ QLabel *label = new QLabel( i18n( "View name:" ), page );
+ layout->addWidget( label, 0, 0 );
+
+ mViewNameEdit = new QLineEdit( page );
+ connect( mViewNameEdit, SIGNAL( textChanged( const QString& ) ),
+ SLOT( textChanged( const QString& ) ) );
+ layout->addWidget( mViewNameEdit, 0, 1 );
+
+ mTypeGroup = new QButtonGroup( 2, Qt::Horizontal, i18n( "View Type" ), page );
+ connect( mTypeGroup, SIGNAL( clicked( int ) ), this, SLOT( clicked( int ) ) );
+ layout->addMultiCellWidget( mTypeGroup, 1, 1, 0, 1 );
+
+ // Now create the radio buttons. This needs some layout work.
+ QDictIterator<ViewFactory> iter( *mViewFactoryDict );
+ for ( iter.toFirst(); iter.current(); ++iter ) {
+//US i am not quit sure, why I can nopt use (*iter)-> here
+//US new QRadioButton( (*iter)->type(), mTypeGroup );
+//US label = new QLabel( (*iter)->description(), mTypeGroup );
+#ifdef DESKTOP_VERSION
+ new QRadioButton( (*iter)->type(), mTypeGroup );
+ label = new QLabel( (*iter)->description(), mTypeGroup );
+#else
+ new QRadioButton( (*iter).type(), mTypeGroup );
+ label = new QLabel( (*iter).description(), mTypeGroup );
+
+#endif
+ label->setAlignment( Qt::AlignLeft | Qt::AlignTop | Qt::WordBreak );
+ }
+
+ mTypeGroup->setButton( 0 );
+ mViewNameEdit->setFocus();
+ enableButton( KDialogBase::Ok, false );
+
+
+}
+
+AddViewDialog::~AddViewDialog()
+{
+}
+
+QString AddViewDialog::viewName()const
+{
+ return mViewNameEdit->text();
+}
+
+QString AddViewDialog::viewType()const
+{
+ return mTypeGroup->find( mTypeId )->text();
+}
+
+void AddViewDialog::clicked( int id )
+{
+ mTypeId = id;
+}
+
+void AddViewDialog::textChanged( const QString &text )
+{
+ enableButton( KDialogBase::Ok, !text.isEmpty() );
+}
+
+#ifndef KAB_EMBEDDED
+#include "addviewdialog.moc"
+#endif //KAB_EMBEDDED
diff --git a/kaddressbook/addviewdialog.h b/kaddressbook/addviewdialog.h
new file mode 100644
index 0000000..8cc12f5
--- a/dev/null
+++ b/kaddressbook/addviewdialog.h
@@ -0,0 +1,73 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef ADDVIEWDIALOG_H
+#define ADDVIEWDIALOG_H
+
+#include <kdialogbase.h>
+#include <qdict.h>
+#include <qstring.h>
+
+class ViewFactory;
+class QButtonGroup;
+class QLineEdit;
+
+
+/**
+ Modal dialog used for adding a new view. The dialog asks for the name of
+ the view as well as the type. Someday it would be nice for this to be a
+ wizard.
+ */
+class AddViewDialog : public KDialogBase
+{
+ Q_OBJECT
+
+ public:
+ AddViewDialog( QDict<ViewFactory> *viewFactoryDict, QWidget *parent,
+ const char *name = 0 );
+ ~AddViewDialog();
+
+ QString viewName()const;
+
+ QString viewType()const ;
+
+ protected slots:
+ /**
+ Called when the user selects a type radio button.
+ */
+ void clicked( int id );
+
+ /**
+ Called when the user changes the text in the name of the view.
+ */
+ void textChanged( const QString &text );
+
+ private:
+ QDict<ViewFactory> *mViewFactoryDict;
+ QLineEdit *mViewNameEdit;
+ QButtonGroup *mTypeGroup;
+
+ int mTypeId;
+};
+
+#endif
diff --git a/kaddressbook/configurewidget.cpp b/kaddressbook/configurewidget.cpp
new file mode 100644
index 0000000..eb57c3a
--- a/dev/null
+++ b/kaddressbook/configurewidget.cpp
@@ -0,0 +1,54 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include <kabc/addressbook.h>
+
+#include "configurewidget.h"
+
+
+ConfigureWidget::ConfigureWidget( KABC::AddressBook *ab, QWidget *parent,
+ const char *name )
+ : QWidget( parent, name ), mAddressBook( ab )
+{
+ //qDebug("new ConfigureWidget %x ", parent);
+}
+
+ConfigureWidget::~ConfigureWidget()
+{
+ //qDebug("ConfigureWidget::~ConfigureWidget() ");
+}
+
+void ConfigureWidget::restoreSettings( KConfig* )
+{
+ // should be reimplemented in the views, extensions etc.
+}
+
+void ConfigureWidget::saveSettings( KConfig* )
+{
+ // should be reimplemented in the views, extensions etc.
+}
+
+KABC::AddressBook *ConfigureWidget::addressBook() const
+{
+ return mAddressBook;
+}
diff --git a/kaddressbook/configurewidget.h b/kaddressbook/configurewidget.h
new file mode 100644
index 0000000..2528c9d
--- a/dev/null
+++ b/kaddressbook/configurewidget.h
@@ -0,0 +1,67 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef CONFIGUREWIDGET_H
+#define CONFIGUREWIDGET_H
+
+
+#include <qwidget.h>
+#include <kconfig.h>
+
+namespace KABC {
+class AddressBook;
+}
+
+class ConfigureWidget : public QWidget
+{
+ public:
+ ConfigureWidget( KABC::AddressBook *ab, QWidget *parent, const char *name = 0 );
+ ~ConfigureWidget();
+
+ /**
+ This method is called before the configure dialog is shown.
+ The widget should reimplement it and fill the GUI with the
+ values from the config file.
+ Important: Don't change the group of cfg!
+ */
+ virtual void restoreSettings( KConfig *cfg );
+
+ /**
+ This method is called after the user clicked the 'Ok' button.
+ The widget should reimplement it and save all values from
+ the GUI to the config file.
+ Important: Don't change the group of cfg!
+ */
+ virtual void saveSettings( KConfig *cfg );
+
+
+ /**
+ Returns a pointer to the address book of this widget.
+ */
+ KABC::AddressBook *addressBook() const;
+
+ private:
+ KABC::AddressBook *mAddressBook;
+};
+
+#endif
diff --git a/kaddressbook/details/detailsviewcontainer.cpp b/kaddressbook/details/detailsviewcontainer.cpp
new file mode 100644
index 0000000..8f566cf
--- a/dev/null
+++ b/kaddressbook/details/detailsviewcontainer.cpp
@@ -0,0 +1,171 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 1996-2002 Mirko Boehm <mirko@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include <qcombobox.h>
+#include <qframe.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qwidgetstack.h>
+
+#include <kapplication.h>
+#include <kdebug.h>
+#include <kdialog.h>
+
+#include "look_basic.h"
+//#include "look_details.h"
+#include "look_html.h"
+
+#ifdef KAB_EMBEDDED
+#include "kabprefs.h"
+#endif //KAB_EMBEDDED
+
+
+#include "detailsviewcontainer.h"
+
+ViewContainer::ViewContainer( QWidget *parent, const char* name )
+ : QWidget( parent, name ), mCurrentLook( 0 )
+{
+ QBoxLayout *topLayout = new QVBoxLayout( this );
+ //topLayout->setMargin( KDialog::marginHint() );
+ //topLayout->setSpacing( KDialog::spacingHint() );
+ topLayout->setMargin( 0 );
+ topLayout->setSpacing( 0 );
+
+ QBoxLayout *styleLayout = new QHBoxLayout( topLayout );
+
+ QLabel *label = new QLabel( i18n("Style:"), this );
+ styleLayout->addWidget( label );
+
+ mStyleCombo = new QComboBox( this );
+ styleLayout->addWidget( mStyleCombo );
+
+ QFrame *frameRuler = new QFrame( this );
+//US frameRuler->setFrameShape( QFrame::HLine );
+//US frameRuler->setFrameShadow( QFrame::Sunken );
+//US topLayout->addWidget( frameRuler );
+
+ mDetailsStack = new QWidgetStack( this );
+ topLayout->addWidget( mDetailsStack, 1 );
+
+ registerLooks();
+
+#if 1
+ // Hide detailed view selection combo box, because we currently have
+ // only one. Reenable it when there are more detailed views.
+ label->hide();
+ mStyleCombo->hide();
+ frameRuler->hide();
+#endif
+}
+
+KABBasicLook *ViewContainer::currentLook()
+{
+ return mCurrentLook;
+}
+
+void ViewContainer::registerLooks()
+{
+ mLookFactories.append( new KABHtmlViewFactory( mDetailsStack ) );
+// mLookFactories.append( new KABDetailedViewFactory( mDetailsStack ) );
+ mStyleCombo->clear();
+
+ for ( uint i = 0; i < mLookFactories.count(); ++i )
+ mStyleCombo->insertItem( mLookFactories.at( i )->description() );
+
+ if ( !mLookFactories.isEmpty() )
+ slotStyleSelected( 0 );
+}
+
+void ViewContainer::slotStyleSelected( int index )
+{
+#ifndef KAB_EMBEDDED
+ KConfig *config = kapp->config();
+#else //KAB_EMBEDDED
+ //US I hope I got the same config object as above expected.
+ KConfig *config = KABPrefs::instance()->getConfig();
+#endif //KAB_EMBEDDED
+ KABC::Addressee addr;
+
+ if ( index >= 0 && index < mStyleCombo->count() ) {
+ if ( mCurrentLook != 0 ) {
+ mCurrentLook->saveSettings( config );
+ addr = mCurrentLook->addressee();
+
+ delete mCurrentLook;
+ mCurrentLook = 0;
+ }
+
+ KABLookFactory *factory = mLookFactories.at( index );
+ kdDebug(5720) << "ViewContainer::slotStyleSelected: "
+ << "creating look "
+ << factory->description() << endl;
+
+ mCurrentLook = factory->create();
+ mDetailsStack->raiseWidget( mCurrentLook );
+
+ connect( mCurrentLook, SIGNAL( sendEmail( const QString& ) ), this,
+ SIGNAL( sendEmail( const QString& ) ) );
+ connect( mCurrentLook, SIGNAL( browse( const QString& ) ), this,
+ SIGNAL( browse( const QString& ) ) );
+ }
+
+ mCurrentLook->restoreSettings( config );
+ mCurrentLook->setAddressee( addr );
+}
+void ViewContainer::refreshView()
+{
+ if ( mCurrentLook )
+ mCurrentLook->setAddressee( mCurrentAddressee );
+}
+
+void ViewContainer::setAddressee( const KABC::Addressee& addressee )
+{
+ if ( mCurrentLook != 0 ) {
+ if ( addressee == mCurrentAddressee )
+ return;
+ else {
+ mCurrentAddressee = addressee;
+ mCurrentLook->setAddressee( mCurrentAddressee );
+ }
+ }
+}
+
+KABC::Addressee ViewContainer::addressee()
+{
+ static KABC::Addressee empty; // do not use!
+
+ if ( !mCurrentLook )
+ return empty;
+ else
+ return mCurrentLook->addressee();
+}
+
+void ViewContainer::setReadOnly( bool state )
+{
+ if ( mCurrentLook )
+ mCurrentLook->setReadOnly( state );
+}
+
+#ifndef KAB_EMBEDDED
+#include "detailsviewcontainer.moc"
+#endif //KAB_EMBEDDED
diff --git a/kaddressbook/details/detailsviewcontainer.h b/kaddressbook/details/detailsviewcontainer.h
new file mode 100644
index 0000000..b561d12
--- a/dev/null
+++ b/kaddressbook/details/detailsviewcontainer.h
@@ -0,0 +1,103 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 1996-2002 Mirko Boehm <mirko@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef DETAILSVIEWCONTAINER_H
+#define DETAILSVIEWCONTAINER_H
+
+#include <qptrlist.h>
+
+#include "look_basic.h"
+
+class QComboBox;
+class QWidgetStack;
+
+class ViewContainer : public QWidget
+{
+ Q_OBJECT
+
+ public:
+ ViewContainer( QWidget *parent = 0, const char* name = 0 );
+
+ /**
+ Return the look currently selected. If there is none, it
+ returns zero. Do not use this pointer to store a reference
+ to a look, the user might select another one (e.g., create
+ a new object) at any time.
+ */
+ KABBasicLook *currentLook();
+ void refreshView();
+ /**
+ Return the contact currently displayed.
+ */
+ KABC::Addressee addressee();
+
+ public slots:
+ /**
+ Set the contact currently displayed.
+ */
+ void setAddressee( const KABC::Addressee& addressee );
+
+ /**
+ Set read-write state.
+ */
+ void setReadOnly( bool state );
+
+ signals:
+ /**
+ The contact has been changed.
+ */
+ void addresseeChanged();
+
+ /**
+ The user acticated the email address displayed. This may happen
+ by, for example, clicking on the displayed mailto-URL.
+ */
+ void sendEmail( const QString& );
+
+ /**
+ The user activated one of the displayed HTTP URLs. For example
+ by clicking on the displayed homepage address.
+ */
+ void browse( const QString& );
+
+ protected:
+ /**
+ A style has been selected. Overloaded from base class.
+ */
+ void slotStyleSelected( int );
+
+ /**
+ Register the available looks.
+ */
+ void registerLooks();
+
+ private:
+ KABC::Addressee mCurrentAddressee;
+ KABBasicLook *mCurrentLook;
+ QPtrList<KABLookFactory> mLookFactories;
+
+ QComboBox *mStyleCombo;
+ QWidgetStack *mDetailsStack;
+};
+
+#endif
diff --git a/kaddressbook/details/global.h b/kaddressbook/details/global.h
new file mode 100644
index 0000000..3c52bc2
--- a/dev/null
+++ b/kaddressbook/details/global.h
@@ -0,0 +1,28 @@
+#ifndef KAB3_GLOBAL_H
+#define KAB3_GLOBAL_H
+
+// keys of configuration file settings:
+
+#define ConfigGeneral "General"
+
+#define ConfigGeneral_RememberLastContact "RememberLastContact"
+#define ConfigGeneral_ShowContactInHeader "ShowContactInHeader"
+
+#define ConfigView "View"
+
+#define ConfigView_View "ConfigView"
+
+#define ConfigView_UseKDEDefaultFonts "UseKDEDefaultFonts"
+#define ConfigView_DefaultBackgroundImage "DefaultBackgroundImage"
+#define ConfigView_DefaultBackgroundColor "DefaultBackgroundColor"
+#define ConfigView_UseDefaultBackground "UseDefaultBackground"
+
+#define ConfigView_HeadlineBGColor "HeadlineBGColor"
+#define ConfigView_UseHeadlineBGColor "UseHeadlineBGColor"
+#define ConfigView_HeadlineTextColor "HeadlineTextColor"
+#define ConfigView_HeadlineFont "HeadlineFont"
+#define ConfigView_BodyFont "BodyFont"
+#define ConfigView_DetailsFont "DetailsFont"
+
+
+#endif
diff --git a/kaddressbook/details/look_basic.cpp b/kaddressbook/details/look_basic.cpp
new file mode 100644
index 0000000..0245686
--- a/dev/null
+++ b/kaddressbook/details/look_basic.cpp
@@ -0,0 +1,75 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 1996-2002 Mirko Boehm <mirko@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include <kdebug.h>
+
+#include "look_basic.h"
+
+KABBasicLook::KABBasicLook( QWidget *parent, const char *name )
+ : QVBox( parent, name ), mReadOnly( false )
+{
+}
+
+void KABBasicLook::setReadOnly( bool state )
+{
+ mReadOnly = state;
+}
+
+bool KABBasicLook::isReadOnly() const
+{
+ return mReadOnly;
+}
+
+void KABBasicLook::setAddressee( const KABC::Addressee &addr )
+{
+ if ( mAddressee == addr )
+ return;
+
+ mAddressee = addr;
+ repaint( false );
+}
+
+KABC::Addressee KABBasicLook::addressee()
+{
+ return mAddressee;
+}
+
+void KABBasicLook::restoreSettings( KConfig* )
+{
+}
+
+void KABBasicLook::saveSettings( KConfig* )
+{
+}
+
+KABLookFactory::KABLookFactory( QWidget *parent, const char *name )
+ : mParent( parent ), mName( name )
+{
+}
+
+KABLookFactory::~KABLookFactory()
+{
+}
+#ifndef KAB_EMBEDDED
+#include "look_basic.moc"
+#endif //KAB_EMBEDDED
diff --git a/kaddressbook/details/look_basic.h b/kaddressbook/details/look_basic.h
new file mode 100644
index 0000000..7e8baff
--- a/dev/null
+++ b/kaddressbook/details/look_basic.h
@@ -0,0 +1,134 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 1996-2002 Mirko Boehm <mirko@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef LOOK_KABBASIC_H
+#define LOOK_KABBASIC_H
+
+#include <kabc/addressbook.h>
+#include <qvbox.h>
+
+class KConfig;
+
+/**
+ This is a pure virtual base class that defines the
+ interface for how to display and change entries of
+ the KDE addressbook.
+
+ This basic widget does not show anything in its client space.
+ Derive it and implement its look and how the user may edit the
+ entry.
+
+ The paintEvent() has to paint the whole widget, since repaint()
+ calls will not delete the widgets background.
+ */
+class KABBasicLook : public QVBox
+{
+ Q_OBJECT
+
+ public:
+ /**
+ The constructor.
+ */
+ KABBasicLook( QWidget *parent = 0, const char *name = 0 );
+
+ /**
+ Set the entry. It will be displayed automatically.
+ */
+ virtual void setAddressee( const KABC::Addressee& addressee );
+
+ /**
+ Get the current entry.
+ */
+ virtual KABC::Addressee addressee();
+
+ /**
+ Configure the view from the configuration file.
+ */
+ virtual void restoreSettings( KConfig* );
+
+ /**
+ Save the view settings to the configuration file.
+ */
+ virtual void saveSettings( KConfig* );
+
+ /**
+ Retrieve read-write state.
+ */
+ bool isReadOnly() const;
+
+ signals:
+ /**
+ This signal is emitted when the user changed the entry.
+ */
+ void entryChanged();
+
+ /**
+ This signal indicates that the entry needs to be changed
+ immidiately in the database. This might be due to changes in
+ values that are available in menus.
+ */
+ void saveMe();
+
+ /**
+ The user acticated the email address displayed. This may happen
+ by, for example, clicking on the displayed mailto-URL.
+ */
+ void sendEmail( const QString &email );
+
+ /**
+ The user activated one of the displayed HTTP URLs. For example
+ by clicking on the displayed homepage address.
+ */
+ void browse( const QString &url );
+
+ public slots:
+ /**
+ Set read-write state.
+ */
+ virtual void setReadOnly( bool state );
+
+ private:
+ KABC::Addressee mAddressee;
+ bool mReadOnly;
+};
+
+class KABLookFactory
+{
+ public:
+ KABLookFactory( QWidget *parent = 0, const char *name = 0 );
+ virtual ~KABLookFactory();
+
+ virtual KABBasicLook *create() = 0;
+
+ /**
+ Overload this method to provide a one-liner description
+ for your look.
+ */
+ virtual QString description() = 0;
+
+ protected:
+ QWidget *mParent;
+ const char* mName;
+};
+
+#endif
diff --git a/kaddressbook/details/look_details.cpp b/kaddressbook/details/look_details.cpp
new file mode 100644
index 0000000..51ec0c0
--- a/dev/null
+++ b/kaddressbook/details/look_details.cpp
@@ -0,0 +1,419 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 1996-2002 Mirko Boehm <mirko@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include <kconfig.h>
+#include <kdebug.h>
+#include <kglobalsettings.h>
+#include <kinstance.h>
+#include <klocale.h>
+#include <kstandarddirs.h>
+
+#include <qcursor.h>
+#include <qdir.h>
+#include <qpainter.h>
+#include <qpopupmenu.h>
+
+#include "global.h"
+#include "kabentrypainter.h"
+
+#include "look_details.h"
+
+#define GRID 5
+
+const QString KABDetailedView::mBorderedBGDir = "kab3part/backgrounds/bordered/";
+const QString KABDetailedView::mTiledBGDir = "kab3part/backgrounds/tiled/";
+
+KABDetailedView::KABDetailedView( QWidget *parent, const char *name )
+ : KABBasicLook( parent, name ), mPainter( 0 ), mBackgroundStyle( None ),
+ mDefaultBGColor( white ), mHeadLineBGColor( darkBlue ),
+ mHeadLineTextColor( yellow ), mGrid( 3 ), mMenuBorderedBG( 0 ),
+ mMenuTiledBG( 0 )
+{
+ KToggleAction** actions[] = {
+ &mActionShowAddresses,
+ &mActionShowEmails,
+ &mActionShowPhones,
+ &mActionShowURLs
+ };
+
+ QString actionTexts[] = {
+ i18n( "Show Postal Addresses" ),
+ i18n( "Show Email Addresses" ),
+ i18n( "Show Telephone Numbers" ),
+ i18n( "Show Web Pages (URLs)" )
+ };
+
+ QFont general = KGlobalSettings::generalFont();
+ QFont fixed = KGlobalSettings::fixedFont();
+ QString gfont = general.family();
+ QString ffont = fixed.family();
+
+ int gpointsize = general.pixelSize();
+ if ( gpointsize == -1 )
+ gpointsize = general.pointSize();
+
+ int fpointsize = fixed.pixelSize();
+ if ( fpointsize == -1 )
+ fpointsize = fixed.pointSize();
+
+ mPainter = new KABEntryPainter;
+
+ mPainter->setForegroundColor( black );
+ mPainter->setHeaderColor( mHeadLineTextColor );
+ mPainter->setUseHeaderColor( mUseHeadLineBGColor );
+ mPainter->setBackgroundColor( mHeadLineBGColor );
+
+ mPainter->setHeaderFont( QFont( gfont, gpointsize + 4, QFont::Bold, true ) );
+ mPainter->setHeadLineFont( QFont( gfont, gpointsize + 2, QFont::Bold, true ) );
+ mPainter->setBodyFont( QFont( gfont, gpointsize, QFont::Normal, false ) );
+ mPainter->setFixedFont( QFont( ffont, fpointsize, QFont::Normal, false ) );
+ mPainter->setCommentFont( QFont( gfont, gpointsize, QFont::Normal, false ) );
+
+ const int numActions = sizeof( actions ) / sizeof( actions[ 0 ] );
+
+ for ( int count = 0; count < numActions; ++count ) {
+ *actions[ count ] = new KToggleAction( actionTexts[ count ] );
+ (*actions[ count ])->setChecked( true );
+ }
+
+ setMouseTracking( true );
+
+ setBackgroundMode( NoBackground );
+}
+
+KABDetailedView::~KABDetailedView()
+{
+ delete mPainter;
+ mPainter = 0;
+}
+
+bool KABDetailedView::getBackground( QString path, QPixmap& image )
+{
+ QMap<QString, QPixmap>::iterator pos;
+
+ pos = mBackgroundMap.find( path );
+ if ( pos == mBackgroundMap.end() ) { // the image has not been loaded previously
+ if ( image.load( path ) ) {
+ mBackgroundMap[ path ] = image;
+ return true;
+ } else
+ return false;
+ } else { // image found in cache
+ image = pos.data();
+ return true;
+ }
+}
+
+void KABDetailedView::paintEvent( QPaintEvent* )
+{
+ const int BorderSpace = mGrid;
+ QPixmap pm( width(), height() );
+ QPainter p;
+
+ QRect entryArea = QRect( BorderSpace, mGrid, width() - mGrid - BorderSpace,
+ height() - 2 * mGrid );
+ p.begin( &pm );
+
+ p.setPen( darkBlue );
+ p.setBrush( mDefaultBGColor );
+ p.drawRect( 0, 0, width(), height() );
+ switch ( mBackgroundStyle ) {
+ case Tiled:
+ p.drawTiledPixmap( 1, 1, width() - 2, height() - 2, mCurrentBackground );
+ break;
+ case Bordered:
+ p.drawTiledPixmap( 1, 1, QMIN( width() - 2, mCurrentBackground.width() ),
+ height() - 2, mCurrentBackground );
+ break;
+ case None: // no BG image defined for this entry:
+ default:
+ if ( mUseDefaultBGImage )
+ p.drawTiledPixmap( 1, 1, width() - 2, height() - 2, mDefaultBGImage );
+ break;
+ };
+
+ p.setViewport( entryArea );
+
+ mPainter->setShowAddresses( mActionShowAddresses->isChecked() );
+ mPainter->setShowEmails( mActionShowEmails->isChecked() );
+ mPainter->setShowPhones( mActionShowPhones->isChecked() );
+ mPainter->setShowURLs( mActionShowURLs->isChecked() );
+ mPainter->printAddressee( addressee(), QRect( 0, 0, entryArea.width(),
+ entryArea.height() ), &p );
+ p.end();
+ bitBlt( this, 0, 0, &pm );
+}
+
+void KABDetailedView::mouseMoveEvent( QMouseEvent *e )
+{
+ QPoint bias( mGrid, mGrid );
+ int rc;
+ bool hit = false;
+
+ if ( ( rc = mPainter->hitsEmail( e->pos() - bias ) ) != -1 )
+ hit = true;
+ else if ( ( rc = mPainter->hitsURL( e->pos() - bias ) ) != -1 )
+ hit = true;
+ else if ( ( rc = mPainter->hitsPhone( e->pos() - bias ) ) != -1 )
+ hit = true;
+ else if ( ( rc = mPainter->hitsTalk( e->pos() - bias ) ) != -1 )
+ hit = true;
+
+ if ( hit ) {
+ if ( cursor().shape() != PointingHandCursor )
+ setCursor( PointingHandCursor );
+ else if( cursor().shape() != ArrowCursor )
+ setCursor(ArrowCursor);
+ }
+}
+
+void KABDetailedView::mousePressEvent( QMouseEvent *e )
+{
+ QPopupMenu menu( this );
+ QPopupMenu *menuBG = new QPopupMenu( &menu );
+ mMenuBorderedBG = new QPopupMenu( &menu );
+ mMenuTiledBG = new QPopupMenu( &menu );
+
+ menu.insertItem( i18n( "Select Background" ), menuBG );
+ menuBG->insertItem( i18n( "Bordered Backgrounds" ), mMenuBorderedBG );
+ menuBG->insertItem( i18n( "Tiled Backgrounds" ), mMenuTiledBG );
+ menu.insertSeparator();
+
+ QPoint point = e->pos() - QPoint( mGrid, mGrid );
+ int rc;
+ QStringList dirsBorderedBG, dirsTiledBG;
+ QDir dir;
+
+ switch( e->button() ) {
+ case QMouseEvent::RightButton:
+ if ( isReadOnly() )
+ menu.setItemEnabled( menu.idAt( 0 ), false );
+ else {
+ // TODO: settings need to be saved in view options
+ dirsBorderedBG = KGlobal::instance()->dirs()->findDirs( "data", mBorderedBGDir );
+ if ( dirsBorderedBG.count() > 0 ) {
+ dir.setPath( dirsBorderedBG[ 0 ] );
+ mBorders = dir.entryList( QDir::Files );
+ for ( uint count = 0; count < mBorders.count(); ++count )
+ mMenuBorderedBG->insertItem( mBorders[ count ], count );
+
+ connect( mMenuBorderedBG, SIGNAL( activated( int ) ),
+ SLOT( slotBorderedBGSelected( int ) ) );
+ } else
+ menuBG->setItemEnabled( menuBG->idAt( 0 ), false );
+
+ dirsTiledBG = KGlobal::instance()->dirs()->findDirs( "data", mTiledBGDir );
+ if ( dirsTiledBG.count() > 0 ) {
+ dir.setPath( dirsTiledBG[ 0 ] );
+ mTiles = dir.entryList( QDir::Files );
+ for ( uint count = 0; count < mTiles.count(); ++count )
+ mMenuTiledBG->insertItem( mTiles[ count ], count );
+
+ connect( mMenuTiledBG, SIGNAL( activated( int ) ),
+ SLOT( slotTiledBGSelected( int ) ) );
+ } else
+ menuBG->setItemEnabled( menuBG->idAt( 1 ), false );
+ }
+
+ mActionShowAddresses->plug( &menu );
+ mActionShowEmails->plug( &menu );
+ mActionShowPhones->plug( &menu );
+ mActionShowURLs->plug( &menu );
+
+ menu.exec( e->globalPos() );
+ break;
+
+ case QMouseEvent::LeftButton:
+ // find whether the pointer touches an email address, URL,
+ // talk address or telephone number:
+ if ( ( rc = mPainter->hitsEmail( point ) ) != -1 ) {
+ emit sendEmail( addressee().emails()[ rc ] );
+ break;
+ }
+ if ( ( rc = mPainter->hitsURL( point ) ) != -1 ) {
+ emit browse( addressee().url().prettyURL() );
+ break;
+ }
+ if ( ( rc = mPainter->hitsPhone( point ) ) != -1 ) {
+ // not implemented yet
+ break;
+ }
+ if ( ( rc = mPainter->hitsTalk( point ) ) != -1 ) {
+ // not implemented yet
+ break;
+ }
+ break;
+ default:
+ break;
+ }
+
+ mMenuBorderedBG = 0;
+ mMenuTiledBG = 0;
+}
+
+void KABDetailedView::setAddressee( const KABC::Addressee &addr )
+{
+ BackgroundStyle style = None;
+ QString dir, file, styleSetting;
+ KABBasicLook::setAddressee( addr );
+
+ // TODO: preload path and styleSetting with possible preference values
+ styleSetting = addressee().custom( "kab", "BackgroundStyle" );
+ style = (BackgroundStyle)styleSetting.toInt();
+ file = addressee().custom( "kab", "BackgroundImage" );
+ if ( !file.isEmpty() ) {
+ switch ( style ) {
+ case Tiled:
+ dir = mTiledBGDir;
+ break;
+ case Bordered:
+ dir = mBorderedBGDir;
+ break;
+ case None:
+ default:
+ break;
+ }
+
+ QStringList dirs = KGlobal::instance()->dirs()->findDirs( "data", dir );
+ mBackgroundStyle = None;
+ if ( !dirs.isEmpty() ) {
+ uint count = 0;
+ for ( ; count < dirs.count(); ++count ) {
+ QDir folder;
+ folder.setPath( dirs[ count ] );
+ file = folder.absPath() + "/" + file;
+ if ( getBackground( file, mCurrentBackground ) ) {
+ mBackgroundStyle = style;
+ break;
+ }
+ }
+
+ if ( count == dirs.count() ) {
+ kdDebug(5720) << "KABDetailedView::setEntry: " << file
+ << " not locatable." << endl;
+ }
+ }
+ } else { // no background here
+ mBackgroundStyle = None;
+ mCurrentBackground.resize( 0, 0 );
+ }
+
+ repaint( false );
+}
+
+void KABDetailedView::slotBorderedBGSelected( int index )
+{
+ if ( index >= 0 && (uint)index < mBorders.count() && !isReadOnly() ) {
+ // get the selection and make it a full path
+ QString path = mBorders[ index ];
+ mBackgroundStyle = Bordered;
+ addressee().insertCustom( "kab", "BackgroundStyle",
+ QString().setNum( mBackgroundStyle ) );
+ addressee().insertCustom( "kab", "BackgroundImage", path );
+ setAddressee( addressee() );
+ }
+}
+
+void KABDetailedView::slotTiledBGSelected( int index )
+{
+ if ( index >= 0 && (uint)index < mTiles.count() && !isReadOnly() ) {
+ QString path = mTiles[ index ];
+ mBackgroundStyle = Tiled;
+ addressee().insertCustom( "kab", "BackgroundStyle",
+ QString().setNum( mBackgroundStyle ) );
+ addressee().insertCustom( "kab", "BackgroundImage", path );
+ setAddressee( addressee() );
+ }
+}
+
+void KABDetailedView::setReadOnly( bool state )
+{
+ KABBasicLook::setReadOnly( state );
+ repaint( false );
+}
+
+void KABDetailedView::restoreSettings( KConfig *config )
+{
+ QFont general = KGlobalSettings::generalFont();
+ QFont fixed = KGlobalSettings::fixedFont();
+ QString gfont = general.family();
+ QString ffont = fixed.family();
+
+ int gpointsize = general.pixelSize();
+ if ( gpointsize == -1 )
+ gpointsize = general.pointSize();
+
+ int fpointsize = fixed.pixelSize();
+ if ( fpointsize == -1 )
+ fpointsize = fixed.pointSize();
+
+ config->setGroup( ConfigView );
+
+ // load the default background image:
+ QString bgImage;
+ mUseDefaultBGImage = config->readBoolEntry( ConfigView_UseDefaultBackground, true );
+ mDefaultBGColor = config->readColorEntry( ConfigView_DefaultBackgroundColor, &white );
+ bgImage = config->readEntry( ConfigView_DefaultBackgroundImage, "konqueror/tiles/kenwimer.png" );
+
+ if ( mUseDefaultBGImage ) {
+ uint count = 0;
+ QStringList dirs = KGlobal::instance()->dirs()->findDirs( "data", "/" );
+ if ( !dirs.isEmpty() ) {
+ for ( count = 0; count < dirs.count(); ++count ) {
+ if ( getBackground( dirs[ count ] + "/" + bgImage, mDefaultBGImage ) )
+ break;
+ }
+ }
+
+ if ( count == dirs.count() ) {
+ mUseDefaultBGImage = getBackground( bgImage, mDefaultBGImage );
+ if ( !mUseDefaultBGImage )
+ kdDebug(5720) << "KABDetailedView::configure: "
+ << "default BG image selected, but could not be loaded."
+ << endl;
+ }
+ }
+
+ mDefaultBGColor = config->readColorEntry( ConfigView_DefaultBackgroundColor, &white );
+ mHeadLineBGColor = config->readColorEntry( ConfigView_HeadlineBGColor, &darkBlue );
+ mHeadLineTextColor = config->readColorEntry( ConfigView_HeadlineTextColor, &yellow );
+ mUseHeadLineBGColor = config->readBoolEntry( ConfigView_UseHeadlineBGColor, true );
+
+ if ( !mPainter )
+ mPainter = new KABEntryPainter;
+
+ mPainter->setForegroundColor( black );
+ mPainter->setHeaderColor( mHeadLineTextColor );
+ mPainter->setUseHeaderColor( mUseHeadLineBGColor );
+ mPainter->setBackgroundColor( mHeadLineBGColor );
+
+ mPainter->setHeaderFont( QFont( gfont, gpointsize + 4, QFont::Bold, true ) );
+ mPainter->setHeadLineFont( QFont( gfont, gpointsize + 2, QFont::Bold, true ) );
+ mPainter->setBodyFont( QFont( gfont, gpointsize, QFont::Normal, false ) );
+ mPainter->setFixedFont( QFont( ffont, fpointsize, QFont::Normal, false ) );
+ mPainter->setCommentFont( QFont( gfont, gpointsize, QFont::Normal, false ) );
+}
+
+#ifndef KAB_EMBEDDED
+#include "look_details.moc"
+#endif //KAB_EMBEDDED
diff --git a/kaddressbook/details/look_details.h b/kaddressbook/details/look_details.h
new file mode 100644
index 0000000..e8d50a9
--- a/dev/null
+++ b/kaddressbook/details/look_details.h
@@ -0,0 +1,157 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 1996-2002 Mirko Boehm <mirko@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef LOOK_DETAILS_H
+#define LOOK_DETAILS_H
+
+#include <kabc/addressbook.h>
+#include <kaction.h>
+#include <klocale.h>
+
+#include <qmap.h>
+#include <qpixmap.h>
+#include <qptrlist.h>
+#include <qrect.h>
+
+#include "look_basic.h"
+
+class KABEntryPainter;
+class QComboBox;
+
+/**
+ This class implements the detailed view.
+ Currently, there is no possibility to change the entry in this
+ view.
+ */
+
+class KABDetailedView : public KABBasicLook
+{
+ Q_OBJECT
+
+ public:
+ /**
+ Enum to select how the background is drawn.
+ */
+ enum BackgroundStyle
+ {
+ None,
+ Tiled,
+ Bordered
+ };
+
+ /**
+ The constructor.
+ */
+ KABDetailedView( QWidget *parent = 0, const char* name = 0 );
+
+ /**
+ The virtual destructor.
+ */
+ virtual ~KABDetailedView();
+
+ /**
+ Set the addressee.
+ */
+ void setAddressee( const KABC::Addressee& );
+
+ /**
+ Overloaded from KABBasicLook.
+ */
+ void setReadOnly( bool );
+
+ /**
+ Overloaded from KABBasicLook.
+ */
+ void restoreSettings( KConfig* );
+
+ public slots:
+ void slotBorderedBGSelected( int index );
+ void slotTiledBGSelected( int index );
+
+ protected:
+ void paintEvent( QPaintEvent* );
+ void mousePressEvent( QMouseEvent* );
+ void mouseMoveEvent( QMouseEvent* );
+
+ /**
+ A method to retrieve a background image according to the path
+ stored in the entry. It is either loaded
+ from backgrounds, that acts as a cache, or from the file
+ and added to @see backgrounds.
+ */
+ bool getBackground( QString path, QPixmap& image );
+
+ private:
+ QPtrList<QRect> mURLRects;
+ QPtrList<QRect> mEmailRects;
+ QPtrList<QRect> mPhoneRects;
+ KABEntryPainter *mPainter;
+
+ QMap<QString, QPixmap> mBackgroundMap;
+ QPixmap mCurrentBackground;
+
+ BackgroundStyle mBackgroundStyle;
+
+ bool mUseDefaultBGImage;
+ bool mUseHeadLineBGColor;
+
+ QColor mDefaultBGColor;
+ QColor mHeadLineBGColor;
+ QColor mHeadLineTextColor;
+
+ QPixmap mDefaultBGImage;
+
+ KToggleAction *mActionShowAddresses;
+ KToggleAction *mActionShowEmails;
+ KToggleAction *mActionShowPhones;
+ KToggleAction *mActionShowURLs;
+
+ const int mGrid;
+ QStringList mBorders;
+ QStringList mTiles;
+
+ QPopupMenu *mMenuBorderedBG;
+ QPopupMenu *mMenuTiledBG;
+
+ static const QString mBorderedBGDir;
+ static const QString mTiledBGDir;
+};
+
+class KABDetailedViewFactory : public KABLookFactory
+{
+ public:
+ KABDetailedViewFactory( QWidget *parent = 0, const char *name = 0 )
+ : KABLookFactory( parent, name ) {}
+
+ KABBasicLook *create()
+ {
+ return new KABDetailedView( mParent, mName );
+ }
+
+ QString description()
+ {
+ return i18n( "Detailed Style: Display all details, no modifications." );
+ }
+};
+
+#endif
diff --git a/kaddressbook/details/look_html.cpp b/kaddressbook/details/look_html.cpp
new file mode 100644
index 0000000..2a70273
--- a/dev/null
+++ b/kaddressbook/details/look_html.cpp
@@ -0,0 +1,45 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include <libkdepim/addresseeview.h>
+
+#include "look_html.h"
+#include <qscrollview.h>
+KABHtmlView::KABHtmlView( QWidget *parent, const char *name )
+ : KABBasicLook( parent, name )
+{
+ mView = new KPIM::AddresseeView( this );
+}
+
+KABHtmlView::~KABHtmlView()
+{
+}
+
+void KABHtmlView::setAddressee( const KABC::Addressee &addr )
+{
+ mView->setAddressee( addr );
+}
+
+#ifndef KAB_EMBEDDED
+#include "look_html.moc"
+#endif //KAB_EMBEDDED
diff --git a/kaddressbook/details/look_html.h b/kaddressbook/details/look_html.h
new file mode 100644
index 0000000..68a02d9
--- a/dev/null
+++ b/kaddressbook/details/look_html.h
@@ -0,0 +1,75 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef LOOK_HTML_H
+#define LOOK_HTML_H
+
+#include <klocale.h>
+
+#include "look_basic.h"
+
+namespace KABC { class Addressee; }
+namespace KPIM { class AddresseeView; }
+
+class KABHtmlView : public KABBasicLook
+{
+ Q_OBJECT
+
+ public:
+ /**
+ The constructor.
+ */
+ KABHtmlView( QWidget *parent = 0, const char* name = 0 );
+
+ /**
+ The virtual destructor.
+ */
+ virtual ~KABHtmlView();
+
+ /**
+ Set the addressee.
+ */
+ void setAddressee( const KABC::Addressee& );
+
+ private:
+ KPIM::AddresseeView *mView;
+};
+
+class KABHtmlViewFactory : public KABLookFactory
+{
+ public:
+ KABHtmlViewFactory( QWidget *parent = 0, const char *name = 0 )
+ : KABLookFactory( parent, name ) {}
+
+ KABBasicLook *create()
+ {
+ return new KABHtmlView( mParent, mName );
+ }
+
+ QString description()
+ {
+ return i18n( "HTML table style." );
+ }
+};
+
+#endif
diff --git a/kaddressbook/emaileditwidget.cpp b/kaddressbook/emaileditwidget.cpp
new file mode 100644
index 0000000..0e01b02
--- a/dev/null
+++ b/kaddressbook/emaileditwidget.cpp
@@ -0,0 +1,275 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include <qcheckbox.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qpushbutton.h>
+#include <qstring.h>
+#include <qtoolbutton.h>
+#include <qtooltip.h>
+#include <qlistbox.h>
+
+#ifndef KAB_EMBEDDED
+#include <kaccelmanager.h>
+#endif //KAB_EMBEDDED
+#include <kconfig.h>
+#include <kcombobox.h>
+#include <kdebug.h>
+#include <kglobal.h>
+#include <kdialog.h>
+#include <kiconloader.h>
+#include <klineedit.h>
+#include <klocale.h>
+#include <kmessagebox.h>
+
+#include "emaileditwidget.h"
+
+EmailEditWidget::EmailEditWidget( QWidget *parent, const char *name )
+ : QWidget( parent, name )
+{
+ QGridLayout *topLayout = new QGridLayout( this, 2, 2 );
+ topLayout->setSpacing( KDialog::spacingHint() );
+ QLabel* label = new QLabel( this );
+
+ label->setPixmap( KGlobal::iconLoader()->loadIcon( "mail_send", KIcon::Desktop, 0) );
+
+ topLayout->addWidget( label, 0, 0 );
+ label->setAlignment( AlignCenter );
+ QPushButton *editButton = new QPushButton( i18n( "Edit Email Addresses..." ), this);
+ topLayout->addWidget( editButton, 0, 1 );
+ label = new QLabel( i18n( "Email:" ), this );
+ topLayout->addWidget( label, 1, 0 );
+
+ mEmailEdit = new KLineEdit( this );
+ connect( mEmailEdit, SIGNAL( textChanged( const QString& ) ),
+ SLOT( textChanged( const QString& ) ) );
+ connect( mEmailEdit, SIGNAL( textChanged( const QString& ) ),
+ SIGNAL( modified() ) );
+ label->setBuddy( mEmailEdit );
+ topLayout->addWidget( mEmailEdit, 1, 1 );
+
+
+ connect( editButton, SIGNAL( clicked() ), SLOT( edit() ) );
+
+ topLayout->activate();
+}
+
+EmailEditWidget::~EmailEditWidget()
+{
+}
+
+void EmailEditWidget::setEmails( const QStringList &list )
+{
+ mEmailList = list;
+
+ bool blocked = mEmailEdit->signalsBlocked();
+ mEmailEdit->blockSignals( true );
+ if ( list.count() > 0 )
+ mEmailEdit->setText( list[ 0 ] );
+ else
+ mEmailEdit->setText( "" );
+ mEmailEdit->blockSignals( blocked );
+}
+
+QStringList EmailEditWidget::emails()
+{
+ if ( mEmailEdit->text().isEmpty() ) {
+ if ( mEmailList.count() > 0 )
+ mEmailList.remove( mEmailList.begin() );
+ } else {
+ if ( mEmailList.count() > 0 )
+ mEmailList.remove( mEmailList.begin() );
+
+ mEmailList.prepend( mEmailEdit->text() );
+ }
+
+ return mEmailList;
+}
+
+void EmailEditWidget::edit()
+{
+ EmailEditDialog dlg( mEmailList, this );
+
+ if ( dlg.exec() ) {
+ if ( dlg.changed() ) {
+ mEmailList = dlg.emails();
+ mEmailEdit->setText( mEmailList[ 0 ] );
+ emit modified();
+ }
+ }
+}
+
+void EmailEditWidget::textChanged( const QString &text )
+{
+ if ( mEmailList.count() > 0 )
+ mEmailList.remove( mEmailList.begin() );
+
+ mEmailList.prepend( text );
+}
+
+
+EmailEditDialog::EmailEditDialog( const QStringList &list, QWidget *parent,
+ const char *name )
+ : KDialogBase( KDialogBase::Plain, i18n( "Edit Email Addresses" ),
+ KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok,
+ parent, name, true )
+{
+ QWidget *page = plainPage();
+
+ QGridLayout *topLayout = new QGridLayout( page, 4, 3 );
+
+ QLabel *label = new QLabel( i18n( "Email address:" ), page );
+ topLayout->addWidget( label, 0, 0 );
+
+ mEmailEdit = new KLineEdit( page );
+ label->setBuddy( mEmailEdit );
+ topLayout->addWidget( mEmailEdit, 0, 1 );
+ connect( mEmailEdit, SIGNAL( returnPressed() ), SLOT( add() ) );
+ connect( mEmailEdit, SIGNAL( textChanged( const QString& ) ),
+ SLOT( emailChanged() ) );
+
+ mAddButton = new QPushButton( i18n( "Add" ), page );
+ mAddButton->setEnabled( false );
+ connect( mAddButton, SIGNAL( clicked() ), SLOT( add() ) );
+ topLayout->addWidget( mAddButton, 0, 2 );
+
+ mEmailListBox = new QListBox( page );
+
+ // Make sure there is room for the scrollbar
+ mEmailListBox->setMinimumHeight( mEmailListBox->sizeHint().height() + 30 );
+ connect( mEmailListBox, SIGNAL( highlighted( int ) ),
+ SLOT( selectionChanged( int ) ) );
+ topLayout->addMultiCellWidget( mEmailListBox, 1, 3, 0, 1 );
+
+ mEditButton = new QPushButton( i18n( "Change" ), page );
+ connect( mEditButton, SIGNAL( clicked() ), SLOT( edit() ) );
+ topLayout->addWidget( mEditButton, 1, 2 );
+
+ mRemoveButton = new QPushButton( i18n( "Remove" ), page );
+ connect( mRemoveButton, SIGNAL( clicked() ), SLOT( remove() ) );
+ topLayout->addWidget( mRemoveButton, 2, 2 );
+
+ mStandardButton = new QPushButton( i18n( "Set Standard" ), page );
+ connect( mStandardButton, SIGNAL( clicked() ), SLOT( standard() ) );
+ topLayout->addWidget( mStandardButton, 3, 2 );
+
+ topLayout->activate();
+ QStringList items = list;
+
+qDebug("EmailEditDialog::EmailEditDialog has to be changed (lowPrio)");
+//US must be fixed !!!
+/*
+ if ( items.remove( "" ) > 0 )
+ mChanged = true;
+ else
+ mChanged = false;
+*/
+
+ mEmailListBox->insertStringList( items );
+ // set default state
+ selectionChanged( -1 );
+
+#ifndef KAB_EMBEDDED
+ KAcceleratorManager::manage( this );
+#else //KAB_EMBEDDED
+//US qDebug("EmailEditDialog::EmailEditDialog has to be changed");
+#endif //KAB_EMBEDDED
+
+}
+
+EmailEditDialog::~EmailEditDialog()
+{
+}
+
+QStringList EmailEditDialog::emails() const
+{
+ QStringList emails;
+
+ for ( uint i = 0; i < mEmailListBox->count(); ++i )
+ emails << mEmailListBox->text( i );
+
+ return emails;
+}
+
+void EmailEditDialog::add()
+{
+ mEmailListBox->insertItem( mEmailEdit->text() );
+
+ mEmailEdit->clear();
+ mEmailEdit->setFocus();
+
+ mChanged = true;
+}
+
+void EmailEditDialog::edit()
+{
+ mEmailEdit->setText( mEmailListBox->currentText() );
+ mEmailEdit->setFocus();
+}
+
+void EmailEditDialog::remove()
+{
+ QString address = mEmailListBox->currentText();
+
+ QString text = i18n( "<qt>Are you sure that you want to remove the email address <b>%1</b>?</qt>" ).arg( address );
+ QString caption = i18n( "Confirm Remove" );
+
+ if ( KMessageBox::questionYesNo( this, text, caption ) == KMessageBox::Yes ) {
+ mEmailListBox->removeItem( mEmailListBox->currentItem() );
+ mChanged = true;
+ }
+}
+
+bool EmailEditDialog::changed() const
+{
+ return mChanged;
+}
+
+void EmailEditDialog::standard()
+{
+ QString text = mEmailListBox->currentText();
+ mEmailListBox->removeItem( mEmailListBox->currentItem() );
+ mEmailListBox->insertItem( text, 0 );
+ mEmailListBox->setSelected( 0, true );
+
+ mChanged = true;
+}
+
+void EmailEditDialog::selectionChanged( int index )
+{
+ bool value = ( index >= 0 ); // An item is selected
+
+ mRemoveButton->setEnabled( value );
+ mEditButton->setEnabled( value );
+ mStandardButton->setEnabled( value );
+}
+
+void EmailEditDialog::emailChanged()
+{
+ mAddButton->setEnabled( !mEmailEdit->text().isEmpty() );
+}
+
+#ifndef KAB_EMBEDDED
+#include "emaileditwidget.moc"
+#endif //KAB_EMBEDDED
diff --git a/kaddressbook/emaileditwidget.h b/kaddressbook/emaileditwidget.h
new file mode 100644
index 0000000..acdecaf
--- a/dev/null
+++ b/kaddressbook/emaileditwidget.h
@@ -0,0 +1,101 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef EMAILEDITWIDGET_H
+#define EMAILEDITWIDGET_H
+
+#include <kabc/addressee.h>
+#include <kdialogbase.h>
+
+#include "addresseeconfig.h"
+
+class QButtonGroup;
+class QCheckBox;
+class QListView;
+class QListBox;
+class QTextEdit;
+class QToolButton;
+
+class KComboBox;
+class KLineEdit;
+class KListView;
+
+/**
+ This widget displays a list box of the email addresses as well as buttons
+ to manipulate them (up, down, add, remove).
+*/
+class EmailEditWidget : public QWidget
+{
+ Q_OBJECT
+
+ public:
+ EmailEditWidget( QWidget *parent, const char *name = 0 );
+ ~EmailEditWidget();
+
+ void setEmails( const QStringList &list );
+ QStringList emails();
+
+ signals:
+ void modified();
+
+ private slots:
+ void edit();
+ void textChanged( const QString& );
+
+ private:
+ KLineEdit *mEmailEdit;
+ QStringList mEmailList;
+};
+
+class EmailEditDialog : public KDialogBase
+{
+ Q_OBJECT
+
+ public:
+ EmailEditDialog( const QStringList &list, QWidget *parent,
+ const char *name = 0 );
+ ~EmailEditDialog();
+
+ QStringList emails() const;
+ bool changed() const;
+
+ protected slots:
+ void add();
+ void remove();
+ void edit();
+ void standard();
+ void selectionChanged( int );
+ void emailChanged();
+
+ private:
+ KLineEdit *mEmailEdit;
+ QListBox *mEmailListBox;
+ QPushButton *mAddButton;
+ QPushButton *mRemoveButton;
+ QPushButton *mEditButton;
+ QPushButton *mStandardButton;
+
+ bool mChanged;
+};
+
+#endif
diff --git a/kaddressbook/extensionmanager.cpp b/kaddressbook/extensionmanager.cpp
new file mode 100644
index 0000000..9114cdc
--- a/dev/null
+++ b/kaddressbook/extensionmanager.cpp
@@ -0,0 +1,246 @@
+/*
+ This file is part of KAddressbook.
+ Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+#include <qlayout.h>
+#include <qapplication.h>
+#include <kactionclasses.h>
+#include <kconfig.h>
+#include <kdebug.h>
+#include <klocale.h>
+
+#ifndef KAB_EMBEDDED
+#include <ktrader.h>
+#else //KAB_EMBEDDED
+#include <features/mergewidget.h>
+#include <features/distributionlistwidget.h>
+#endif //KAB_EMBEDDED
+
+#include "addresseeeditorwidget.h"
+#include "kabcore.h"
+#include "kabprefs.h"
+
+#include "extensionmanager.h"
+
+ExtensionManager::ExtensionManager( KABCore *core, QWidget *parent,
+ const char *name )
+ : QScrollView( parent, name ), mCore( core ), mCurrentExtensionWidget( 0 )
+{
+#ifdef KAB_EMBEDDED
+//US QPopupMenu *settingsmenu = (QPopupMenu*)mCore->getSettingsMenu();
+ QWidget *settingsmenu = (QWidget*)mCore->getSettingsMenu();
+#endif //KAB_EMBEDDED
+
+ mActionExtensions = new KSelectAction( i18n( "Show Extension Bar" ), 0,
+ mCore->actionCollection(),
+ "options_show_extensions" );
+
+ mActionExtensions->plug( settingsmenu );
+
+ connect( mActionExtensions, SIGNAL( activated( int ) ),
+ SLOT( setActiveExtension( int ) ) );
+ mWidgetBox = new QWidget( viewport() );
+ addChild( mWidgetBox );
+ setResizePolicy(AutoOneFit);
+ createExtensionWidgets();
+ hide();
+}
+
+ExtensionManager::~ExtensionManager()
+{
+}
+
+void ExtensionManager::restoreSettings()
+{
+ mActionExtensions->setCurrentItem( KABPrefs::instance()->mCurrentExtension );
+ int i = 1;
+ mCurrentExtensionWidget = mExtensionWidgetList.at( i-1 );
+ while ( mCurrentExtensionWidget ) {
+ if( i != KABPrefs::instance()->mCurrentExtension )
+ mCurrentExtensionWidget->hide();
+ mCurrentExtensionWidget = mExtensionWidgetList.at( ++i-1 );
+
+ }
+ setActiveExtension( mActionExtensions->currentItem() );
+}
+
+void ExtensionManager::saveSettings()
+{
+ KABPrefs::instance()->mCurrentExtension = mActionExtensions->currentItem();
+}
+
+void ExtensionManager::reconfigure()
+{
+ saveSettings();
+ createExtensionWidgets();
+ restoreSettings();
+}
+
+bool ExtensionManager::isQuickEditVisible() const
+{
+ return ( mCurrentExtensionWidget &&
+ mCurrentExtensionWidget->identifier() == "contact_editor" );
+}
+
+void ExtensionManager::setSelectionChanged()
+{
+ if ( mCurrentExtensionWidget )
+ mCurrentExtensionWidget->contactsSelectionChanged();
+}
+
+void ExtensionManager::setActiveExtension( int id )
+{
+ //qDebug("+++++++++++++++++++ExtensionManager::setActiveExtension %d ", id);
+ if ( id == 0 ) {
+ hide();
+ mCurrentExtensionWidget = 0;
+#ifndef DESKTOP_VERSION
+//US our screen is so small, that we better hide the detailscreen, just in case.
+ mCore->setDetailsToState( );
+#endif //KAB_EMBEDDED
+ } else if ( id > 0 ) {
+ if ( mCurrentExtensionWidget )
+ mCurrentExtensionWidget->hide();
+
+ mCurrentExtensionWidget = mExtensionWidgetList.at( id - 1 );
+
+ if ( mCurrentExtensionWidget ) {
+#ifndef DESKTOP_VERSION
+//US our screen is so small, that we better hide the detailscreen, just in case.
+ mCore->setDetailsVisible( false );
+#endif //KAB_EMBEDDED
+ show();
+ mWidgetBox->show();
+ mCurrentExtensionWidget->show();
+ } else {
+ hide();
+ mCurrentExtensionWidget = 0;
+#ifndef DESKTOP_VERSION
+//US our screen is so small, that we better hide the detailscreen, just in case.
+ mCore->setDetailsToState( );
+#endif //KAB_EMBEDDED
+ }
+ }
+}
+
+void ExtensionManager::createExtensionWidgets()
+{
+ // clear extension widget list
+ mExtensionWidgetList.setAutoDelete( true );
+ QPtrListIterator<ExtensionWidget> wdgIt( mExtensionWidgetList );
+ ExtensionWidget *wdg = 0;
+ while ( ( wdg = wdgIt.current() ) != 0 )
+ mExtensionWidgetList.remove( wdg );
+
+ mExtensionWidgetList.setAutoDelete( false );
+
+ QStringList extensionNames( i18n( "None" ) );
+
+ // add addressee editor as default
+
+ QHBoxLayout *hbl = new QHBoxLayout (mWidgetBox );
+
+ wdg = new AddresseeEditorWidget( mCore, true, mWidgetBox );
+ hbl->addWidget( wdg );
+ //wdg->hide();
+ connect( wdg, SIGNAL( modified( const KABC::Addressee::List& ) ),
+ SIGNAL( modified( const KABC::Addressee::List& ) ) );
+ mExtensionWidgetList.append( wdg );
+ extensionNames.append( wdg->title() );
+
+ // load the other extensions
+ QStringList activeExtensions = KABPrefs::instance()->mActiveExtensions;
+
+#ifndef KAB_EMBEDDED
+ KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/Extension" );
+ KTrader::OfferList::ConstIterator it;
+ for ( it = plugins.begin(); it != plugins.end(); ++it ) {
+ if ( !(*it)->hasServiceType( "KAddressBook/Extension" ) )
+ continue;
+
+ KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() );
+ if ( !factory ) {
+ kdDebug(5720) << "ExtensionManager::loadExtensions(): Factory creation failed" << endl;
+ continue;
+ }
+
+ ExtensionFactory *extensionFactory = static_cast<ExtensionFactory*>( factory );
+
+ if ( !extensionFactory ) {
+ kdDebug(5720) << "ExtensionManager::loadExtensions(): Cast failed" << endl;
+ continue;
+ }
+
+ if ( !activeExtensions.contains( extensionFactory->identifier() ) )
+ continue;
+
+ wdg = extensionFactory->extension( mCore, this );
+ if ( wdg ) {
+ //wdg->hide();
+ connect( wdg, SIGNAL( modified( const KABC::Addressee::List& ) ),
+ SIGNAL( modified( const KABC::Addressee::List& ) ) );
+ mExtensionWidgetList.append( wdg );
+ extensionNames.append( wdg->title() );
+ }
+ }
+#else //KAB_EMBEDDED
+ //load Mergefactory/extension
+ ExtensionFactory *extensionFactory = new MergeFactory();
+ if ( activeExtensions.contains( extensionFactory->identifier() ) )
+ {
+ wdg = extensionFactory->extension( mCore, mWidgetBox );
+ if ( wdg ) {
+ hbl->addWidget( wdg );
+ //wdg->hide();
+ connect( wdg, SIGNAL( modified( const KABC::Addressee::List& ) ),
+ SIGNAL( modified( const KABC::Addressee::List& ) ) );
+ mExtensionWidgetList.append( wdg );
+ extensionNames.append( wdg->title() );
+ }
+ }
+
+ //load DistributionListfactory/extension
+ extensionFactory = new DistributionListFactory();
+ if (activeExtensions.contains( extensionFactory->identifier() ) )
+ {
+ wdg = extensionFactory->extension( mCore, mWidgetBox );
+ if ( wdg ) {
+ hbl->addWidget( wdg );
+ //wdg->hide();
+ connect( wdg, SIGNAL( modified( const KABC::Addressee::List& ) ),
+ SIGNAL( modified( const KABC::Addressee::List& ) ) );
+ mExtensionWidgetList.append( wdg );
+ extensionNames.append( wdg->title() );
+ }
+ }
+
+ hbl->addStretch();
+
+#endif //KAB_EMBEDDED
+
+
+ mActionExtensions->setItems( extensionNames );
+ mCurrentExtensionWidget = 0;
+}
+
+#ifndef KAB_EMBEDDED
+#include "extensionmanager.moc"
+#endif //KAB_EMBEDDED
diff --git a/kaddressbook/extensionmanager.h b/kaddressbook/extensionmanager.h
new file mode 100644
index 0000000..8f64a50
--- a/dev/null
+++ b/kaddressbook/extensionmanager.h
@@ -0,0 +1,88 @@
+/*
+ This file is part of KAddressbook.
+ Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef EXTENSIONMANAGER_H
+#define EXTENSIONMANAGER_H
+
+#include <qhbox.h>
+#include <qscrollview.h>
+#include <qptrlist.h>
+
+#include <extensionwidget.h>
+
+class KABCore;
+class KSelectAction;
+
+
+class ExtensionManager : public QScrollView
+{
+ Q_OBJECT
+
+ public:
+ ExtensionManager( KABCore *core, QWidget *parent, const char *name = 0 );
+ ~ExtensionManager();
+
+ /**
+ Restores the extension manager specific settings.
+ */
+ void restoreSettings();
+
+ /**
+ Saves the extension manager specific settings.
+ */
+ void saveSettings();
+
+ /**
+ Rereads the extension manager specific settings with some
+ additional initialization stuff.
+ */
+ void reconfigure();
+
+ /**
+ Returns whether the quickedit extension is currently visible.
+ */
+ bool isQuickEditVisible() const;
+
+ public slots:
+ void setSelectionChanged();
+
+ signals:
+ void modified( const KABC::Addressee::List& );
+
+ private slots:
+ void setActiveExtension( int id );
+
+ private:
+ void createExtensionWidgets();
+
+ KABCore *mCore;
+ QWidget *mWidgetBox;
+
+ ExtensionWidget *mCurrentExtensionWidget;
+ QPtrList<ExtensionWidget> mExtensionWidgetList;
+
+ KSelectAction *mActionExtensions;
+
+};
+
+#endif
diff --git a/kaddressbook/extensionwidget.cpp b/kaddressbook/extensionwidget.cpp
new file mode 100644
index 0000000..69f4aa8
--- a/dev/null
+++ b/kaddressbook/extensionwidget.cpp
@@ -0,0 +1,84 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include "configurewidget.h"
+#include "kabcore.h"
+
+#include "extensionwidget.h"
+
+ExtensionWidget::ExtensionWidget( KABCore *core, QWidget *parent,
+ const char *name )
+ : QWidget( parent, name ), mCore( core )
+{
+}
+
+ExtensionWidget::~ExtensionWidget()
+{
+}
+
+KABCore *ExtensionWidget::core() const
+{
+ return mCore;
+}
+
+bool ExtensionWidget::contactsSelected() const
+{
+ return mCore->selectedUIDs().count() != 0;
+}
+
+KABC::Addressee::List ExtensionWidget::selectedContacts()
+{
+ KABC::Addressee::List list;
+
+ QStringList uids = mCore->selectedUIDs();
+ QStringList::Iterator it;
+ for ( it = uids.begin(); it != uids.end(); ++it )
+ list.append( mCore->addressBook()->findByUid( *it ) );
+
+ return list;
+}
+
+void ExtensionWidget::contactsSelectionChanged()
+{
+ // do nothing
+}
+
+QString ExtensionWidget::title() const
+{
+ return "<bug!!!>";
+}
+
+QString ExtensionWidget::identifier() const
+{
+ return "<bug!!!>";
+}
+
+ConfigureWidget *ExtensionFactory::configureWidget( QWidget*, const char* )
+{
+ return 0;
+}
+
+#ifndef KAB_EMBEDDED
+#include "extensionwidget.moc"
+#endif //KAB_EMBEDDED
+
diff --git a/kaddressbook/extensionwidget.h b/kaddressbook/extensionwidget.h
new file mode 100644
index 0000000..fc91f21
--- a/dev/null
+++ b/kaddressbook/extensionwidget.h
@@ -0,0 +1,119 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef EXTENSIONWIDGET_H
+#define EXTENSIONWIDGET_H
+
+#include <qwidget.h>
+
+#include <kabc/addressbook.h>
+#ifndef KAB_EMBEDDED
+#include <klibloader.h>
+#endif //KAB_EMBEDDED
+
+class ConfigureWidget;
+class KABCore;
+
+class ExtensionWidget : public QWidget
+{
+ Q_OBJECT
+
+ public:
+ ExtensionWidget( KABCore *core, QWidget *parent, const char *name = 0 );
+ ~ExtensionWidget();
+
+ /**
+ @return A pointer to the core object
+ */
+ KABCore *core() const;
+
+ /**
+ Returns whether there are selected contacts in the view.
+ */
+ bool contactsSelected() const;
+
+ /**
+ Returns a list of contacts that are selected in the view.
+ Use @ref addresseesSelected() to test if there exists selected
+ contacts.
+ */
+ KABC::Addressee::List selectedContacts();
+
+ /**
+ This method is called whenever the selection in the view changed.
+ */
+ virtual void contactsSelectionChanged();
+
+ /**
+ This method should be reimplemented and return the i18ned title of this
+ widget.
+ */
+ virtual QString title() const;
+
+ /**
+ This method should be reimplemented and return a unique identifier.
+ */
+ virtual QString identifier() const;
+
+ signals:
+ void modified( const KABC::Addressee::List &list );
+
+ private:
+ KABCore *mCore;
+
+ class ExtensionWidgetPrivate;
+ ExtensionWidgetPrivate *d;
+};
+
+#ifndef KAB_EMBEDDED
+//MOC_SKIP_BEGIN
+class ExtensionFactory : public KLibFactory
+//MOC_SKIP_END
+#else //KAB_EMBEDDED
+class ExtensionFactory
+#endif //KAB_EMBEDDED
+{
+ public:
+ virtual ExtensionWidget *extension( KABCore *core, QWidget *parent,
+ const char *name = 0 ) = 0;
+
+ virtual ConfigureWidget *configureWidget( QWidget *parent,
+ const char *name = 0 );
+
+ virtual bool configureWidgetAvailable() { return false; }
+
+ /**
+ This method should return the same identifier like the config
+ widget.
+ */
+ virtual QString identifier() const = 0;
+
+ protected:
+ virtual QObject* createObject( QObject*, const char*, const char*,
+ const QStringList & )
+ {
+ return 0;
+ }
+};
+
+#endif
diff --git a/kaddressbook/features/distributionlistwidget.cpp b/kaddressbook/features/distributionlistwidget.cpp
new file mode 100644
index 0000000..bfcb121
--- a/dev/null
+++ b/kaddressbook/features/distributionlistwidget.cpp
@@ -0,0 +1,501 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include <qbuttongroup.h>
+#include <qcombobox.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qlistview.h>
+#include <qpushbutton.h>
+#include <qradiobutton.h>
+
+#ifndef KAB_EMBEDDED
+#include <kaccelmanager.h>
+#endif //KAB_EMBEDDED
+
+
+#include <kdebug.h>
+#include <klineeditdlg.h>
+#include <klocale.h>
+#include <kglobal.h>
+#include <kmessagebox.h>
+
+#include <kabc/addressbook.h>
+#include <kabc/addresseedialog.h>
+#include <kabc/distributionlist.h>
+#include <kabc/vcardconverter.h>
+
+#ifndef KAB_EMBEDDED
+#include <libkdepim/kvcarddrag.h>
+#endif //KAB_EMBEDDED
+
+#include "kabcore.h"
+
+#include "distributionlistwidget.h"
+
+#ifndef KAB_EMBEDDED
+
+class DistributionListFactory : public ExtensionFactory
+{
+ public:
+ ExtensionWidget *extension( KABCore *core, QWidget *parent, const char *name )
+ {
+ return new DistributionListWidget( core, parent, name );
+ }
+
+ QString identifier() const
+ {
+ return "distribution_list_editor";
+ }
+};
+
+extern "C" {
+ void *init_libkaddrbk_distributionlist()
+ {
+ return ( new DistributionListFactory );
+ }
+}
+#endif //KAB_EMBEDDED
+
+class ContactItem : public QListViewItem
+{
+ public:
+ ContactItem( DistributionListView *parent, const KABC::Addressee &addressee,
+ const QString &email = QString::null ) :
+ QListViewItem( parent ),
+ mAddressee( addressee ),
+ mEmail( email )
+ {
+ setText( 0, addressee.realName() );
+ if( email.isEmpty() ) {
+ setText( 1, addressee.preferredEmail() );
+ setText( 2, i18n( "Yes" ) );
+ } else {
+ setText( 1, email );
+ setText( 2, i18n( "No" ) );
+ }
+ }
+
+ KABC::Addressee addressee() const
+ {
+ return mAddressee;
+ }
+
+ QString email() const
+ {
+ return mEmail;
+ }
+
+ protected:
+ bool acceptDrop( const QMimeSource* )
+ {
+ return true;
+ }
+
+ private:
+ KABC::Addressee mAddressee;
+ QString mEmail;
+};
+
+DistributionListWidget::DistributionListWidget( KABCore *core, QWidget *parent,
+ const char *name )
+ : ExtensionWidget( core, parent, name ), mManager( 0 )
+{
+ QGridLayout *topLayout = new QGridLayout( this, 3, 4, KDialog::marginHint(),
+ KDialog::spacingHint() );
+
+ if (KGlobal::getOrientation() == KGlobal::Portrait)
+ {
+ mCreateListButton = new QPushButton( i18n( "New List" ), this );
+ mEditListButton = new QPushButton( i18n( "Ren List" ), this );
+ mRemoveListButton = new QPushButton( i18n( "Del List" ), this );
+ mAddContactButton = new QPushButton( i18n( "Add Cont." ), this );
+ mChangeEmailButton = new QPushButton( i18n( "Chge Email" ), this );
+ mRemoveContactButton = new QPushButton( i18n( "Del Cont." ), this );
+ }
+ else
+ {
+ mCreateListButton = new QPushButton( i18n( "New List..." ), this );
+ mEditListButton = new QPushButton( i18n( "Rename List..." ), this );
+ mRemoveListButton = new QPushButton( i18n( "Remove List" ), this );
+ mAddContactButton = new QPushButton( i18n( "Add Contact" ), this );
+ mChangeEmailButton = new QPushButton( i18n( "Change Email..." ), this );
+ mRemoveContactButton = new QPushButton( i18n( "Remove Contact" ), this );
+ }
+ mNameCombo = new QComboBox( this );
+ topLayout->addWidget( mNameCombo, 0, 0 );
+ connect( mNameCombo, SIGNAL( activated( int ) ), SLOT( updateContactView() ) );
+
+ topLayout->addWidget( mCreateListButton, 0, 1 );
+ connect( mCreateListButton, SIGNAL( clicked() ), SLOT( createList() ) );
+
+ topLayout->addWidget( mEditListButton, 0, 2 );
+ connect( mEditListButton, SIGNAL( clicked() ), SLOT( editList() ) );
+
+ topLayout->addWidget( mRemoveListButton, 0, 3 );
+ connect( mRemoveListButton, SIGNAL( clicked() ), SLOT( removeList() ) );
+
+ mContactView = new DistributionListView( this );
+ mContactView->addColumn( i18n( "Name" ) );
+ mContactView->addColumn( i18n( "Email" ) );
+ mContactView->addColumn( i18n( "Use Preferred" ) );
+ mContactView->setEnabled( false );
+ mContactView->setAllColumnsShowFocus( true );
+ mContactView->setMinimumHeight( 30 );
+
+ topLayout->addMultiCellWidget( mContactView, 1, 1, 0, 3 );
+ connect( mContactView, SIGNAL( selectionChanged() ),
+ SLOT( selectionContactViewChanged() ) );
+ connect( mContactView, SIGNAL( dropped( QDropEvent*, QListViewItem* ) ),
+ SLOT( dropped( QDropEvent*, QListViewItem* ) ) );
+
+ mAddContactButton->setEnabled( false );
+ topLayout->addWidget( mAddContactButton, 2, 0 );
+ connect( mAddContactButton, SIGNAL( clicked() ), SLOT( addContact() ) );
+
+ topLayout->addWidget( mChangeEmailButton, 2, 2 );
+ connect( mChangeEmailButton, SIGNAL( clicked() ), SLOT( changeEmail() ) );
+
+ topLayout->addWidget( mRemoveContactButton, 2, 3 );
+ connect( mRemoveContactButton, SIGNAL( clicked() ), SLOT( removeContact() ) );
+
+ mManager = new KABC::DistributionListManager( core->addressBook() );
+ mManager->load();
+
+ updateNameCombo();
+
+#ifdef KAB_EMBEDDED
+// if (KGlobal::getOrientation() == KGlobal::Portrait)
+// parent->setMaximumSize( KGlobal::getDesktopWidth() , 150);
+#endif //KAB_EMBEDDED
+
+#ifndef KAB_EMBEDDED
+ KAcceleratorManager::manage( this );
+#endif //KAB_EMBEDDED
+}
+
+DistributionListWidget::~DistributionListWidget()
+{
+ delete mManager;
+}
+
+void DistributionListWidget::save()
+{
+qDebug("DistributionListWidget::save");
+ mManager->save();
+}
+
+void DistributionListWidget::selectionContactViewChanged()
+{
+ ContactItem *contactItem =
+ static_cast<ContactItem *>( mContactView->selectedItem() );
+ bool state = contactItem;
+
+ mChangeEmailButton->setEnabled( state );
+ mRemoveContactButton->setEnabled( state );
+}
+
+void DistributionListWidget::createList()
+{
+ KLineEditDlg dlg( i18n( "Please enter name:" ), QString::null, this );
+#ifdef KAB_EMBEDDED
+ dlg.setFixedSize(200, 50);
+#endif //KAB_EMBEDDED
+ dlg.setCaption( i18n( "New Distribution List" ) );
+ if ( !dlg.exec() )
+ return;
+
+ new KABC::DistributionList( mManager, dlg.text() );
+
+ mNameCombo->clear();
+ mNameCombo->insertStringList( mManager->listNames() );
+ mNameCombo->setCurrentItem( mNameCombo->count() - 1 );
+
+ updateContactView();
+
+ changed();
+}
+
+void DistributionListWidget::editList()
+{
+ QString oldName = mNameCombo->currentText();
+
+ KLineEditDlg dlg( i18n( "Please change name:" ), oldName, this );
+#ifdef KAB_EMBEDDED
+ dlg.setFixedSize(200, 50);
+#endif //KAB_EMBEDDED
+ dlg.setCaption( i18n("Distribution List") );
+ if ( !dlg.exec() )
+ return;
+
+ KABC::DistributionList *list = mManager->list( oldName );
+ list->setName( dlg.text() );
+
+ mNameCombo->clear();
+ mNameCombo->insertStringList( mManager->listNames() );
+ mNameCombo->setCurrentItem( mNameCombo->count() - 1 );
+
+ updateContactView();
+
+ changed();
+}
+
+void DistributionListWidget::removeList()
+{
+ int result = KMessageBox::warningContinueCancel( this,
+ i18n( "<qt>Delete distribution list <b>%1</b>?</qt>" ) .arg( mNameCombo->currentText() ),
+ QString::null, i18n( "Delete" ) );
+
+ if ( result != KMessageBox::Continue )
+ return;
+
+ delete mManager->list( mNameCombo->currentText() );
+ mNameCombo->removeItem( mNameCombo->currentItem() );
+
+ updateContactView();
+
+ changed();
+}
+
+void DistributionListWidget::addContact()
+{
+ KABC::DistributionList *list = mManager->list( mNameCombo->currentText() );
+ if ( !list )
+ return;
+
+ KABC::Addressee::List addrList = selectedContacts();
+ KABC::Addressee::List::Iterator it;
+ for ( it = addrList.begin(); it != addrList.end(); ++it )
+ list->insertEntry( *it );
+
+ updateContactView();
+
+ changed();
+}
+
+void DistributionListWidget::removeContact()
+{
+ KABC::DistributionList *list = mManager->list( mNameCombo->currentText() );
+ if ( !list )
+ return;
+
+ ContactItem *contactItem =
+ static_cast<ContactItem *>( mContactView->selectedItem() );
+ if ( !contactItem )
+ return;
+
+ list->removeEntry( contactItem->addressee(), contactItem->email() );
+ delete contactItem;
+
+ changed();
+}
+
+void DistributionListWidget::changeEmail()
+{
+ KABC::DistributionList *list = mManager->list( mNameCombo->currentText() );
+ if ( !list )
+ return;
+
+ ContactItem *contactItem =
+ static_cast<ContactItem *>( mContactView->selectedItem() );
+ if ( !contactItem )
+ return;
+
+ QString email = EmailSelector::getEmail( contactItem->addressee().emails(),
+ contactItem->email(), this );
+ list->removeEntry( contactItem->addressee(), contactItem->email() );
+ list->insertEntry( contactItem->addressee(), email );
+
+ updateContactView();
+
+ changed();
+}
+
+void DistributionListWidget::updateContactView()
+{
+ mContactView->clear();
+
+ KABC::DistributionList *list = mManager->list( mNameCombo->currentText() );
+ if ( !list ) {
+ mEditListButton->setEnabled( false );
+ mRemoveListButton->setEnabled( false );
+ mChangeEmailButton->setEnabled( false );
+ mRemoveContactButton->setEnabled( false );
+ mContactView->setEnabled( false );
+ return;
+ } else {
+ mEditListButton->setEnabled( true );
+ mRemoveListButton->setEnabled( true );
+ mContactView->setEnabled( true );
+ }
+
+ KABC::DistributionList::Entry::List entries = list->entries();
+ KABC::DistributionList::Entry::List::ConstIterator it;
+ for( it = entries.begin(); it != entries.end(); ++it )
+ new ContactItem( mContactView, (*it).addressee, (*it).email );
+
+ ContactItem *contactItem =
+ static_cast<ContactItem *>( mContactView->selectedItem() );
+ bool state = contactItem;
+
+ mChangeEmailButton->setEnabled( state );
+ mRemoveContactButton->setEnabled( state );
+}
+
+void DistributionListWidget::updateNameCombo()
+{
+ mNameCombo->insertStringList( mManager->listNames() );
+
+ updateContactView();
+}
+
+void DistributionListWidget::dropEvent( QDropEvent *e )
+{
+ KABC::DistributionList *distributionList = mManager->list( mNameCombo->currentText() );
+ if ( !distributionList )
+ return;
+
+ QString vcards;
+#ifndef KAB_EMBEDDED
+ if ( KVCardDrag::decode( e, vcards ) ) {
+#endif //KAB_EMBEDDED
+ QStringList list = QStringList::split( "\r\n\r\n", vcards );
+ QStringList::Iterator it;
+ KABC::VCardConverter converter;
+ for ( it = list.begin(); it != list.end(); ++it ) {
+ KABC::Addressee addr;
+ if ( converter.vCardToAddressee( (*it).stripWhiteSpace(), addr ) )
+ distributionList->insertEntry( addr );
+ }
+
+ changed();
+ updateContactView();
+#ifndef KAB_EMBEDDED
+ }
+#endif //KAB_EMBEDDED
+}
+
+void DistributionListWidget::contactsSelectionChanged()
+{
+ mAddContactButton->setEnabled( contactsSelected() && mNameCombo->count() > 0 );
+}
+
+QString DistributionListWidget::title() const
+{
+ return i18n( "Distribution List Editor" );
+}
+
+QString DistributionListWidget::identifier() const
+{
+ return "distribution_list_editor";
+}
+
+void DistributionListWidget::dropped( QDropEvent *e, QListViewItem* )
+{
+ dropEvent( e );
+}
+
+void DistributionListWidget::changed()
+{
+ save();
+}
+
+
+DistributionListView::DistributionListView( QWidget *parent, const char* name )
+ : KListView( parent, name )
+{
+ setDragEnabled( true );
+ setAcceptDrops( true );
+ setAllColumnsShowFocus( true );
+}
+
+void DistributionListView::dragEnterEvent( QDragEnterEvent* e )
+{
+#ifndef KAB_EMBEDDED
+ bool canDecode = QTextDrag::canDecode( e );
+ e->accept( canDecode );
+#endif //KAB_EMBEDDED
+}
+
+void DistributionListView::viewportDragMoveEvent( QDragMoveEvent *e )
+{
+#ifndef KAB_EMBEDDED
+ bool canDecode = QTextDrag::canDecode( e );
+ e->accept( canDecode );
+#endif //KAB_EMBEDDED
+}
+
+void DistributionListView::viewportDropEvent( QDropEvent *e )
+{
+ emit dropped( e, 0 );
+}
+
+void DistributionListView::dropEvent( QDropEvent *e )
+{
+ emit dropped( e, 0 );
+}
+
+
+EmailSelector::EmailSelector( const QStringList &emails,
+ const QString &current, QWidget *parent )
+ : KDialogBase( KDialogBase::Plain, i18n("Select Email Address"), Ok, Ok,
+ parent )
+{
+ QFrame *topFrame = plainPage();
+ QBoxLayout *topLayout = new QVBoxLayout( topFrame );
+
+ mButtonGroup = new QButtonGroup( 1, Horizontal, i18n("Email Addresses"),
+ topFrame );
+ topLayout->addWidget( mButtonGroup );
+
+ QStringList::ConstIterator it;
+ for( it = emails.begin(); it != emails.end(); ++it ) {
+ QRadioButton *button = new QRadioButton( *it, mButtonGroup );
+ if ( (*it) == current ) {
+ button->setDown( true );
+ }
+ }
+}
+
+QString EmailSelector::selected()
+{
+ QButton *button = mButtonGroup->selected();
+ if ( button )
+ return button->text();
+
+ return QString::null;
+}
+
+QString EmailSelector::getEmail( const QStringList &emails,
+ const QString &current, QWidget *parent )
+{
+ EmailSelector dlg( emails, current, parent );
+ dlg.exec();
+
+ return dlg.selected();
+}
+
+
+#ifndef KAB_EMBEDDED
+#include "distributionlistwidget.moc"
+#endif //KAB_EMBEDDED
diff --git a/kaddressbook/features/distributionlistwidget.h b/kaddressbook/features/distributionlistwidget.h
new file mode 100644
index 0000000..82bac3d
--- a/dev/null
+++ b/kaddressbook/features/distributionlistwidget.h
@@ -0,0 +1,143 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef DISTRIBUTIONLISTWIDGET_H
+#define DISTRIBUTIONLISTWIDGET_H
+
+#include <kdialogbase.h>
+#include <klistview.h>
+
+#include "extensionwidget.h"
+
+class QButtonGroup;
+class QComboBox;
+class QLabel;
+class QListView;
+
+class DistributionListView;
+class KABCore;
+
+namespace KABC {
+class AddressBook;
+class DistributionListManager;
+}
+
+class DistributionListWidget : public ExtensionWidget
+{
+ Q_OBJECT
+
+ public:
+ DistributionListWidget( KABCore*, QWidget *parent, const char *name = 0 );
+ virtual ~DistributionListWidget();
+
+ void contactsSelectionChanged();
+
+ QString title() const;
+ QString identifier() const;
+
+ public slots:
+ void save();
+ void dropped( QDropEvent*, QListViewItem* );
+
+ private slots:
+ void createList();
+ void editList();
+ void removeList();
+ void addContact();
+ void removeContact();
+ void changeEmail();
+ void updateNameCombo();
+ void updateContactView();
+ void selectionContactViewChanged();
+ void changed();
+
+ protected:
+ void dropEvent( QDropEvent* );
+
+ private:
+ QComboBox *mNameCombo;
+ QLabel *mListLabel;
+ DistributionListView *mContactView;
+
+ KABC::DistributionListManager *mManager;
+ QPushButton *mCreateListButton;
+ QPushButton *mEditListButton;
+ QPushButton *mRemoveListButton;
+ QPushButton *mChangeEmailButton;
+ QPushButton *mAddContactButton;
+ QPushButton *mRemoveContactButton;
+};
+
+/**
+ @short Helper class
+*/
+class DistributionListView : public KListView
+{
+ Q_OBJECT
+
+ public:
+ DistributionListView( QWidget *parent, const char* name = 0 );
+
+ protected:
+ void dragEnterEvent( QDragEnterEvent *e );
+ void dropEvent( QDropEvent *e );
+ void viewportDragMoveEvent( QDragMoveEvent *e );
+ void viewportDropEvent( QDropEvent *e );
+};
+
+/**
+ @short Helper class
+*/
+class EmailSelector : public KDialogBase
+{
+ public:
+ EmailSelector( const QStringList &emails, const QString &current,
+ QWidget *parent );
+
+ QString selected();
+
+ static QString getEmail( const QStringList &emails, const QString &current,
+ QWidget *parent );
+
+ private:
+ QButtonGroup *mButtonGroup;
+};
+
+
+#ifdef KAB_EMBEDDED
+class DistributionListFactory : public ExtensionFactory
+{
+ public:
+ ExtensionWidget *extension( KABCore *core, QWidget *parent, const char *name )
+ {
+ return new DistributionListWidget( core, parent, name );
+ }
+
+ QString identifier() const
+ {
+ return "distribution_list_editor";
+ }
+};
+#endif //KAB_EMBEDDED
+
+#endif
diff --git a/kaddressbook/features/mergewidget.cpp b/kaddressbook/features/mergewidget.cpp
new file mode 100644
index 0000000..2476e42
--- a/dev/null
+++ b/kaddressbook/features/mergewidget.cpp
@@ -0,0 +1,374 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include <qlayout.h>
+#include <qpushbutton.h>
+
+#ifndef KAB_EMBEDDED
+#include <kaccelmanager.h>
+#endif //KAB_EMBEDDED
+
+#include <kdebug.h>
+#include <klistview.h>
+#include <klocale.h>
+#include <kglobal.h>
+#include <kmessagebox.h>
+
+#include <kabc/addressbook.h>
+
+#include "kabcore.h"
+
+#include "mergewidget.h"
+
+#ifndef KAB_EMBEDDED
+class MergeFactory : public ExtensionFactory
+{
+ public:
+ ExtensionWidget *extension( KABCore *core, QWidget *parent, const char *name )
+ {
+ return new MergeWidget( core, parent, name );
+ }
+
+ QString identifier() const
+ {
+ return "merge";
+ }
+};
+
+extern "C" {
+ void *init_libkaddrbk_merge()
+ {
+ return ( new MergeFactory );
+ }
+}
+#endif //KAB_EMBEDDED
+
+class ContactItem : public QListViewItem
+{
+ public:
+ ContactItem( KListView *parent, const KABC::Addressee &addressee )
+ : QListViewItem( parent ), mAddressee( addressee )
+ {
+ KABC::Field::List fieldList = KABC::Field::defaultFields();
+ KABC::Field::List::ConstIterator it;
+
+ int i = 0;
+ for ( it = fieldList.begin(); it != fieldList.end(); ++it )
+ setText( i++, (*it)->value( mAddressee ) );
+ }
+
+ KABC::Addressee addressee() const
+ {
+ return mAddressee;
+ }
+
+ private:
+ KABC::Addressee mAddressee;
+};
+
+MergeWidget::MergeWidget( KABCore *core, QWidget *parent, const char *name )
+ : ExtensionWidget( core, parent, name ), mBlockUpdate( false )
+{
+#ifdef KAB_EMBEDDED
+ if (KGlobal::getOrientation() == KGlobal::Portrait)
+ parent->setMaximumSize( KGlobal::getDesktopWidth() , 180);
+#endif //KAB_EMBEDDED
+
+ QGridLayout *topLayout = new QGridLayout( this, 3, 2, KDialog::marginHint(),
+ KDialog::spacingHint() );
+
+ mContactView = new KListView( this );
+ KABC::Field::List fieldList = KABC::Field::defaultFields();
+ KABC::Field::List::ConstIterator it;
+
+ for ( it = fieldList.begin(); it != fieldList.end(); ++it )
+ mContactView->addColumn( (*it)->label() );
+
+ mContactView->setEnabled( false );
+ mContactView->setAllColumnsShowFocus( true );
+ topLayout->addMultiCellWidget( mContactView, 0, 2, 0, 0 );
+
+ connect( mContactView, SIGNAL( selectionChanged() ),
+ SLOT( selectionContactViewChanged() ) );
+
+ mMergeAndRemoveButton = new QPushButton( i18n( "Merge and Remove" ), this );
+ mMergeAndRemoveButton->setEnabled( false );
+ topLayout->addWidget( mMergeAndRemoveButton, 0, 1 );
+ connect( mMergeAndRemoveButton, SIGNAL( clicked() ), SLOT( mergeAndRemove() ) );
+
+ mMergeButton = new QPushButton( i18n( "Merge" ), this );
+ mMergeButton->setEnabled( false );
+ topLayout->addWidget( mMergeButton, 1, 1 );
+ connect( mMergeButton, SIGNAL( clicked() ), SLOT( merge() ) );
+
+#ifndef KAB_EMBEDDED
+ KAcceleratorManager::manage( this );
+#endif //KAB_EMBEDDED
+}
+
+MergeWidget::~MergeWidget()
+{
+}
+
+void MergeWidget::selectionContactViewChanged()
+{
+#ifndef KAB_EMBEDDED
+ ContactItem *contactItem =
+ dynamic_cast<ContactItem*>( mContactView->selectedItem() );
+#else //KAB_EMBEDDED
+ ContactItem *contactItem =(ContactItem*)( mContactView->selectedItem() );
+#endif //KAB_EMBEDDED
+
+ bool state = (contactItem != 0);
+
+ mMergeAndRemoveButton->setEnabled( state );
+ mMergeButton->setEnabled( state );
+}
+
+void MergeWidget::contactsSelectionChanged()
+{
+ if ( mBlockUpdate )
+ return;
+
+ if ( !contactsSelected() ) {
+ mContactView->setEnabled( false );
+ mContactView->clear();
+ mMergeAndRemoveButton->setEnabled( false );
+ mMergeButton->setEnabled( false );
+ } else {
+ KABC::Addressee::List list = selectedContacts();
+ if ( list.count() > 1 ) {
+ mContactView->setEnabled( false );
+ mContactView->clear();
+ mMergeAndRemoveButton->setEnabled( false );
+ mMergeButton->setEnabled( false );
+ return;
+ } else {
+ mContactView->setEnabled( true );
+ mMasterAddressee = list[ 0 ];
+ updateView();
+ }
+ }
+}
+
+void MergeWidget::updateView()
+{
+ mContactView->clear();
+
+ KABC::AddressBook::Iterator it;
+ KABC::AddressBook *ab = core()->addressBook();
+ if ( !ab )
+ return;
+
+ for ( it = ab->begin(); it != ab->end(); ++it )
+ if ( (*it).uid() != mMasterAddressee.uid() )
+ new ContactItem( mContactView, *it );
+}
+
+QString MergeWidget::title() const
+{
+ return i18n( "Merge Contacts Editor" );
+}
+
+QString MergeWidget::identifier() const
+{
+ return "merge";
+}
+
+void MergeWidget::mergeAndRemove()
+{
+#ifndef KAB_EMBEDDED
+ ContactItem *item = dynamic_cast<ContactItem*>( mContactView->currentItem() );
+#else //KAB_EMBEDDED
+ ContactItem *item = (ContactItem*)( mContactView->currentItem() );
+#endif //KAB_EMBEDDED
+ if ( !item )
+ return;
+
+ QString oldUID = item->addressee().uid();
+
+ doMerge( item->addressee() );
+
+ KABC::Addressee::List retval;
+ retval << mMasterAddressee;
+ emit modified( retval );
+
+ mBlockUpdate = true;
+ core()->deleteContacts( oldUID );
+ core()->setContactSelected( mMasterAddressee.uid() );
+ mBlockUpdate = false;
+
+ updateView();
+}
+
+void MergeWidget::merge()
+{
+#ifndef KAB_EMBEDDED
+ ContactItem *item = dynamic_cast<ContactItem*>( mContactView->currentItem() );
+#else //KAB_EMBEDDED
+ ContactItem *item = (ContactItem*)( mContactView->currentItem() );
+#endif //KAB_EMBEDDED
+ if ( !item )
+ return;
+
+ doMerge( item->addressee() );
+
+ KABC::Addressee::List retval;
+ retval << mMasterAddressee;
+ emit modified( retval );
+
+ mBlockUpdate = true;
+ core()->setContactSelected( mMasterAddressee.uid() );
+ mBlockUpdate = false;
+
+ updateView();
+}
+
+void MergeWidget::doMerge( const KABC::Addressee &addr )
+{
+ // ADR + LABEL
+ KABC::Address::List addresses = addr.addresses();
+ KABC::Address::List masterAddresses = mMasterAddressee.addresses();
+ KABC::Address::List::Iterator addrIt ;
+ for ( addrIt = addresses.begin(); addrIt != addresses.end(); ++addrIt ) {
+ if ( !masterAddresses.contains( *addrIt ) )
+ mMasterAddressee.insertAddress( *addrIt );
+ }
+
+ if ( mMasterAddressee.birthday().isNull() && !addr.birthday().isNull() )
+ mMasterAddressee.setBirthday( addr.birthday() );
+
+
+ // CATEGORIES
+ QStringList::Iterator it;
+ QStringList categories = addr.categories();
+ QStringList masterCategories = mMasterAddressee.categories();
+ QStringList newCategories( masterCategories );
+ for ( it = categories.begin(); it != categories.end(); ++it )
+ if ( !masterCategories.contains( *it ) )
+ newCategories.append( *it );
+ mMasterAddressee.setCategories( newCategories );
+
+ // CLASS
+ if ( !mMasterAddressee.secrecy().isValid() && addr.secrecy().isValid() )
+ mMasterAddressee.setSecrecy( addr.secrecy() );
+
+ // EMAIL
+ QStringList emails = addr.emails();
+ QStringList masterEmails = mMasterAddressee.emails();
+ for ( it = emails.begin(); it != emails.end(); ++it )
+ if ( !masterEmails.contains( *it ) )
+ mMasterAddressee.insertEmail( *it, false );
+
+ // FN
+ if ( mMasterAddressee.formattedName().isEmpty() && !addr.formattedName().isEmpty() )
+ mMasterAddressee.setFormattedName( addr.formattedName() );
+
+ // GEO
+ if ( !mMasterAddressee.geo().isValid() && addr.geo().isValid() )
+ mMasterAddressee.setGeo( addr.geo() );
+
+/*
+ // KEY
+ // LOGO
+*/
+
+ // MAILER
+ if ( mMasterAddressee.mailer().isEmpty() && !addr.mailer().isEmpty() )
+ mMasterAddressee.setMailer( addr.mailer() );
+
+ // N
+ if ( mMasterAddressee.assembledName().isEmpty() && !addr.assembledName().isEmpty() )
+ mMasterAddressee.setNameFromString( addr.assembledName() );
+
+ // NICKNAME
+ if ( mMasterAddressee.nickName().isEmpty() && !addr.nickName().isEmpty() )
+ mMasterAddressee.setNickName( addr.nickName() );
+
+ // NOTE
+ if ( mMasterAddressee.note().isEmpty() && !addr.note().isEmpty() )
+ mMasterAddressee.setNote( addr.note() );
+
+ // ORG
+ if ( mMasterAddressee.organization().isEmpty() && !addr.organization().isEmpty() )
+ mMasterAddressee.setOrganization( addr.organization() );
+
+/*
+ // PHOTO
+*/
+
+ // PROID
+ if ( mMasterAddressee.productId().isEmpty() && !addr.productId().isEmpty() )
+ mMasterAddressee.setProductId( addr.productId() );
+
+ // REV
+ if ( mMasterAddressee.revision().isNull() && !addr.revision().isNull() )
+ mMasterAddressee.setRevision( addr.revision() );
+
+ // ROLE
+ if ( mMasterAddressee.role().isEmpty() && !addr.role().isEmpty() )
+ mMasterAddressee.setRole( addr.role() );
+
+ // SORT-STRING
+ if ( mMasterAddressee.sortString().isEmpty() && !addr.sortString().isEmpty() )
+ mMasterAddressee.setSortString( addr.sortString() );
+
+/*
+ // SOUND
+*/
+
+ // TEL
+ KABC::PhoneNumber::List phones = addr.phoneNumbers();
+ KABC::PhoneNumber::List masterPhones = mMasterAddressee.phoneNumbers();
+ KABC::PhoneNumber::List::ConstIterator phoneIt;
+ for ( phoneIt = phones.begin(); phoneIt != phones.end(); ++phoneIt )
+ if ( !masterPhones.contains( *it ) )
+ mMasterAddressee.insertPhoneNumber( *it );
+
+ // TITLE
+ if ( mMasterAddressee.title().isEmpty() && !addr.title().isEmpty() )
+ mMasterAddressee.setTitle( addr.title() );
+
+ // TZ
+ if ( !mMasterAddressee.timeZone().isValid() && addr.timeZone().isValid() )
+ mMasterAddressee.setTimeZone( addr.timeZone() );
+
+ // UID // ignore UID
+
+ // URL
+ if ( mMasterAddressee.url().isEmpty() && !addr.url().isEmpty() )
+ mMasterAddressee.setUrl( addr.url() );
+
+ // X-
+ QStringList customs = addr.customs();
+ QStringList masterCustoms = mMasterAddressee.customs();
+ QStringList newCustoms( masterCustoms );
+ for ( it = customs.begin(); it != customs.end(); ++it )
+ if ( !masterCustoms.contains( *it ) )
+ newCustoms.append( *it );
+ mMasterAddressee.setCustoms( newCustoms );
+}
+
+#ifndef KAB_EMBEDDED
+#include "mergewidget.moc"
+#endif //KAB_EMBEDDED
diff --git a/kaddressbook/features/mergewidget.h b/kaddressbook/features/mergewidget.h
new file mode 100644
index 0000000..1063c80
--- a/dev/null
+++ b/kaddressbook/features/mergewidget.h
@@ -0,0 +1,87 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef MERGEWIDGET_H
+#define MERGEWIDGET_H
+
+#include <kdialogbase.h>
+#include <klistview.h>
+
+#include "extensionwidget.h"
+
+class QListView;
+
+class KABCore;
+
+namespace KABC {
+class AddressBook;
+}
+
+class MergeWidget : public ExtensionWidget
+{
+ Q_OBJECT
+
+ public:
+ MergeWidget( KABCore*, QWidget *parent, const char *name = 0 );
+ virtual ~MergeWidget();
+
+ void contactsSelectionChanged();
+
+ QString title() const;
+ QString identifier() const;
+
+ private slots:
+ void mergeAndRemove();
+ void merge();
+
+ void selectionContactViewChanged();
+
+ private:
+ void updateView();
+ void doMerge( const KABC::Addressee &addr );
+
+ KListView *mContactView;
+ QPushButton *mMergeAndRemoveButton;
+ QPushButton *mMergeButton;
+
+ KABC::Addressee mMasterAddressee;
+ bool mBlockUpdate;
+};
+
+#ifdef KAB_EMBEDDED
+class MergeFactory : public ExtensionFactory
+{
+ public:
+ ExtensionWidget *extension( KABCore *core, QWidget *parent, const char *name )
+ {
+ return new MergeWidget( core, parent, name );
+ }
+
+ QString identifier() const
+ {
+ return "merge";
+ }
+};
+#endif //KAB_EMBEDDED
+
+#endif
diff --git a/kaddressbook/filter.cpp b/kaddressbook/filter.cpp
new file mode 100644
index 0000000..b0d04ca
--- a/dev/null
+++ b/kaddressbook/filter.cpp
@@ -0,0 +1,205 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include <kconfig.h>
+#include <kconfigbase.h>
+#include <kdebug.h>
+
+#include "kabprefs.h"
+
+#include "filter.h"
+
+Filter::Filter()
+ : mName( QString::null ), mMatchRule( Matching ), mEnabled( true ),
+ mInternal( false )
+{
+}
+
+Filter::Filter( const QString &name )
+ : mName( name ), mMatchRule( Matching ), mEnabled( true ),
+ mInternal( false )
+{
+}
+
+Filter::~Filter()
+{
+}
+
+void Filter::setName( const QString &name )
+{
+ mName = name;
+}
+
+const QString &Filter::name() const
+{
+ return mName;
+}
+
+bool Filter::isInternal() const
+{
+ return mInternal;
+}
+
+void Filter::apply( KABC::Addressee::List &addresseeList )
+{
+ KABC::Addressee::List::Iterator iter;
+ for ( iter = addresseeList.begin(); iter != addresseeList.end(); ) {
+ if ( filterAddressee( *iter ) )
+ ++iter;
+ else
+ {
+#ifndef KAB_EMBEDDED
+ iter = addresseeList.erase( iter );
+#else //KAB_EMBEDDED
+ iter = addresseeList.remove( iter );
+#endif //KAB_EMBEDDED
+ }
+ }
+}
+
+bool Filter::filterAddressee( const KABC::Addressee &a )
+{
+ QStringList::Iterator iter;
+ iter = mCategoryList.begin();
+ // empty filter always matches
+
+ if ( iter == mCategoryList.end() )
+ return true;
+
+ for ( ; iter != mCategoryList.end(); ++iter ) {
+ if ( a.hasCategory( *iter ) )
+ return ( mMatchRule == Matching );
+ }
+
+ return !( mMatchRule == Matching );
+}
+
+void Filter::setEnabled( bool on )
+{
+ mEnabled = on;
+}
+
+bool Filter::isEnabled() const
+{
+ return mEnabled;
+}
+
+void Filter::setCategories( const QStringList &list )
+{
+ mCategoryList = list;
+}
+
+const QStringList &Filter::categories() const
+{
+ return mCategoryList;
+}
+
+void Filter::save( KConfig *config )
+{
+ config->writeEntry( "Name", mName );
+ config->writeEntry( "Enabled", mEnabled );
+ config->writeEntry( "Categories", mCategoryList );
+ config->writeEntry( "MatchRule", (int)mMatchRule );
+}
+
+void Filter::restore( KConfig *config )
+{
+ mName = config->readEntry( "Name", "<internal error>" );
+ mEnabled = config->readBoolEntry( "Enabled", true );
+ mCategoryList = config->readListEntry( "Categories" );
+ mMatchRule = (MatchRule)config->readNumEntry( "MatchRule", Matching );
+}
+
+void Filter::save( KConfig *config, QString baseGroup, Filter::List &list )
+{
+ {
+ KConfigGroupSaver s( config, baseGroup );
+
+ // remove the old filters
+ uint count = config->readNumEntry( "Count" );
+ /* // memory access violation here
+ for ( uint i = 0; i < count; ++i )
+ config->deleteGroup( QString( "%1_%2" ).arg( baseGroup ).arg( i ) );
+ */
+ }
+
+ int index = 0;
+ Filter::List::Iterator iter;
+ for ( iter = list.begin(); iter != list.end(); ++iter ) {
+ if ( !(*iter).mInternal ) {
+ KConfigGroupSaver s( config, QString( "%1_%2" ).arg( baseGroup ).arg( index ) );
+
+ (*iter).save( config );
+ index++;
+ }
+ }
+
+ KConfigGroupSaver s( config, baseGroup );
+
+ config->writeEntry( "Count", index );
+
+}
+
+Filter::List Filter::restore( KConfig *config, QString baseGroup )
+{
+ Filter::List list;
+ int count = 0;
+ Filter f;
+
+ {
+ KConfigGroupSaver s( config, baseGroup );
+ count = config->readNumEntry( "Count", 0 );
+ }
+
+ for ( int i = 0; i < count; i++ ) {
+ {
+ KConfigGroupSaver s( config, QString( "%1_%2" ).arg( baseGroup ).arg( i ) );
+ f.restore( config );
+ }
+
+ list.append( f );
+ }
+
+ QStringList cats = KABPrefs::instance()->mCustomCategories;
+ for ( QStringList::Iterator it = cats.begin(); it != cats.end(); ++it ) {
+ Filter filter;
+ filter.mName = *it;
+ filter.mEnabled = true;
+ filter.mCategoryList = *it;
+ filter.mMatchRule = Matching;
+ filter.mInternal = true;
+ list.append( filter );
+ }
+
+ return list;
+}
+
+void Filter::setMatchRule( MatchRule rule )
+{
+ mMatchRule = rule;
+}
+
+Filter::MatchRule Filter::matchRule() const
+{
+ return mMatchRule;
+}
diff --git a/kaddressbook/filter.h b/kaddressbook/filter.h
new file mode 100644
index 0000000..cf2c0a1
--- a/dev/null
+++ b/kaddressbook/filter.h
@@ -0,0 +1,153 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef FILTER_H
+#define FILTER_H
+
+#include <qstring.h>
+#include <qstringlist.h>
+#include <qvaluelist.h>
+
+#include <kabc/addressee.h>
+#include <kconfig.h>
+
+/**
+ Filter for AddressBook related objects (Addressees)
+
+ @todo This class should be switched to use shared data.
+ */
+class Filter
+{
+ public:
+ typedef QValueList<Filter> List;
+
+ enum MatchRule { Matching = 0, NotMatching = 1 };
+
+ Filter();
+ Filter( const QString& name );
+ ~Filter();
+
+ /**
+ Set the name of the filter.
+ */
+ void setName( const QString &name );
+
+ /**
+ @return The name of the filter.
+ */
+ const QString &name() const;
+
+ /**
+ @return Whether the filter is an internal one.
+ */
+ bool isInternal() const;
+
+ /**
+ Apply the filter to the addressee list. All addressees not passing
+ the filter criterias will be removed from the list.
+
+ If the MatchRule is NotMatch, then all the addressees matching the
+ filter will be removed from the list.
+ */
+ void apply( KABC::Addressee::List &addresseeList );
+
+ /**
+ Apply the filter to the addressee.
+
+ @return True if the addressee passes the criteria, false otherwise.
+ The return values are opposite if the MatchRule is NotMatch.
+ */
+ bool filterAddressee( const KABC::Addressee &a );
+
+ /**
+ Enable or disable the filter
+ */
+ void setEnabled( bool on );
+
+ /**
+ @return True if this filter is enabled, false otherwise.
+ */
+ bool isEnabled() const;
+
+ /**
+ Set the list of categories. This list is used to filter addressees.
+ */
+ void setCategories( const QStringList &list );
+
+ /**
+ @return The list of categories.
+ */
+ const QStringList &categories() const;
+
+ /**
+ Saves the filter to the config file. The group should already be set.
+ */
+ void save( KConfig *config );
+
+ /**
+ Loads the filter from the config file. The group should already be set.
+ */
+ void restore( KConfig *config );
+
+ /**
+ Saves a list of filters to the config file.
+
+ @param config The config file to use
+ @param baseGroup The base groupname to use. The number of filters
+ will be written to this group, then a _1, _2, etc
+ will be append for each filter saved.
+ @param list The list of filters to be saved.
+ */
+ static void save( KConfig *config, QString baseGroup, Filter::List &list );
+
+ /**
+ Restores a list of filters from a config file.
+
+ @param config The config file to read from.
+ @param baseGroup The base group name to be used to find the filters
+
+ @return The list of filters.
+ */
+ static Filter::List restore( KConfig *config, QString baseGroup );
+
+ /**
+ Sets the filter rule. If the rule is Filter::Matching (default),
+ then the filter will return true on items that match the filter.
+ If the rule is Filter::NotMatching, then the filter will return
+ true on items that do not match the filter.
+ */
+ void setMatchRule( MatchRule rule );
+
+ /** @return The current match rule.
+ */
+ MatchRule matchRule() const;
+
+ private:
+ QString mName;
+ QStringList mCategoryList;
+ MatchRule mMatchRule;
+ bool mEnabled;
+ bool mInternal;
+};
+
+#endif
diff --git a/kaddressbook/filtereditdialog.cpp b/kaddressbook/filtereditdialog.cpp
new file mode 100644
index 0000000..063585a
--- a/dev/null
+++ b/kaddressbook/filtereditdialog.cpp
@@ -0,0 +1,302 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+/*
+Enhanced Version of the file for platform independent KDE tools.
+Copyright (c) 2004 Ulf Schenk
+
+$Id$
+*/
+
+#include <qbuttongroup.h>
+#include <qhbox.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qpushbutton.h>
+#include <qradiobutton.h>
+#include <qregexp.h>
+#include <qstring.h>
+#include <qtoolbutton.h>
+#include <qtooltip.h>
+#include <qwidget.h>
+
+#include <kapplication.h>
+#include <kbuttonbox.h>
+#include <kdebug.h>
+#include <kiconloader.h>
+#include <klineedit.h>
+#include <klistbox.h>
+#include <klistview.h>
+#include <klocale.h>
+#include <kglobal.h>
+
+#include "kabprefs.h"
+#include "filtereditdialog.h"
+
+FilterEditDialog::FilterEditDialog( QWidget *parent, const char *name )
+ : KDialogBase( Plain, i18n( "Edit Address Book Filter" ),
+ Help | Ok | Cancel, Ok, parent, name, /*US false*/ true, true )
+{
+ initGUI();
+
+ QStringList cats = KABPrefs::instance()->mCustomCategories;
+
+ QStringList::Iterator iter;
+ for ( iter = cats.begin(); iter != cats.end(); ++iter )
+ mCategoriesView->insertItem( new QCheckListItem( mCategoriesView, (*iter), QCheckListItem::CheckBox ) );
+ filterNameTextChanged( mNameEdit->text() );
+}
+
+FilterEditDialog::~FilterEditDialog()
+{
+}
+
+void FilterEditDialog::setFilter( const Filter &filter )
+{
+ mNameEdit->setText( filter.name() );
+
+ QStringList categories = filter.categories();
+ QListViewItem *item = mCategoriesView->firstChild();
+ while ( item != 0 ) {
+ if ( categories.contains( item->text( 0 ) ) ) {
+ QCheckListItem *checkItem = static_cast<QCheckListItem*>( item );
+ checkItem->setOn( true );
+ }
+
+ item = item->nextSibling();
+ }
+
+ if ( filter.matchRule() == Filter::Matching )
+ mMatchRuleGroup->setButton( 0 );
+ else
+ mMatchRuleGroup->setButton( 1 );
+}
+
+Filter FilterEditDialog::filter()
+{
+ Filter filter;
+
+ filter.setName( mNameEdit->text() );
+
+ QStringList categories;
+ QListViewItem *item = mCategoriesView->firstChild();
+ while ( item != 0 ) {
+ QCheckListItem *checkItem = static_cast<QCheckListItem*>( item );
+ if ( checkItem->isOn() )
+ categories.append( item->text( 0 ) );
+
+ item = item->nextSibling();
+ }
+ filter.setCategories( categories );
+
+ if ( mMatchRuleGroup->find( 0 )->isOn() )
+ filter.setMatchRule( Filter::Matching );
+ else
+ filter.setMatchRule( Filter::NotMatching );
+
+ return filter;
+}
+
+void FilterEditDialog::initGUI()
+{
+#ifndef KAB_EMBEDDED
+ resize( 490, 300 );
+#else //KAB_EMBEDDED
+ resize( KMIN(KGlobal::getDesktopWidth()-10, 490), KMIN(KGlobal::getDesktopHeight()-50, 300));
+#endif //KAB_EMBEDDED
+
+
+ QWidget *page = plainPage();
+ QLabel *label;
+
+ QGridLayout *topLayout = new QGridLayout( page, 3, 2, 0, spacingHint() );
+
+ label = new QLabel( i18n( "Name" ), page );
+ mNameEdit = new KLineEdit( page );
+ mNameEdit->setFocus();
+ topLayout->addWidget( label, 0, 0 );
+ topLayout->addWidget( mNameEdit, 0, 1 );
+ connect( mNameEdit, SIGNAL( textChanged( const QString& ) ),
+ SLOT( filterNameTextChanged( const QString&) ) );
+
+ mCategoriesView = new KListView( page );
+ mCategoriesView->addColumn( i18n( "Categories" ) );
+ topLayout->addMultiCellWidget( mCategoriesView, 1, 1, 0, 1 );
+
+ mMatchRuleGroup = new QButtonGroup( page );
+ mMatchRuleGroup->setExclusive( true );
+
+ QBoxLayout *gbLayout = new QVBoxLayout( mMatchRuleGroup );
+ gbLayout->setSpacing( KDialog::spacingHint() );
+ gbLayout->setMargin( KDialog::marginHint() );
+
+ QRadioButton *radio = new QRadioButton( i18n( "Show only contacts matching\n the selected categories" ), mMatchRuleGroup );
+ radio->setChecked( true );
+ mMatchRuleGroup->insert( radio );
+ gbLayout->addWidget( radio );
+
+ radio = new QRadioButton( i18n( "Show all contacts except those\n matching the selected categories" ), mMatchRuleGroup );
+ mMatchRuleGroup->insert( radio );
+ gbLayout->addWidget( radio );
+
+ topLayout->addMultiCellWidget( mMatchRuleGroup, 2, 2, 0, 1 );
+}
+
+void FilterEditDialog::filterNameTextChanged( const QString &text )
+{
+ enableButtonOK( !text.isEmpty() );
+}
+
+void FilterEditDialog::slotHelp()
+{
+#ifndef KAB_EMBEDDED
+ kapp->invokeHelp( "using-filters" );
+#endif //KAB_EMBEDDED
+}
+
+FilterDialog::FilterDialog( QWidget *parent, const char *name )
+ : KDialogBase( Plain, i18n( "Edit Address Book Filters" ),
+ Ok | Cancel, Ok, parent, name, /*US false*/true, true )
+{
+ initGUI();
+}
+
+FilterDialog::~FilterDialog()
+{
+}
+
+void FilterDialog::setFilters( const Filter::List &list )
+{
+ mFilterList.clear();
+ mInternalFilterList.clear();
+
+ Filter::List::ConstIterator it;
+ for ( it = list.begin(); it != list.end(); ++it ) {
+ if ( (*it).isInternal() )
+ mInternalFilterList.append( *it );
+ else
+ mFilterList.append( *it );
+ }
+
+ refresh();
+}
+
+Filter::List FilterDialog::filters() const
+{
+ Filter::List list = mFilterList + mInternalFilterList;
+ return list;
+}
+
+void FilterDialog::add()
+{
+#ifndef KAB_EMBEDDED
+ FilterEditDialog dlg( this );
+#else //KAB_EMBEDDED
+ FilterEditDialog dlg( this->parentWidget() );
+#endif //KAB_EMBEDDED
+
+ if ( dlg.exec() )
+ mFilterList.append( dlg.filter() );
+
+ refresh();
+
+ mFilterListBox->setCurrentItem( mFilterListBox->count() - 1 );
+}
+
+void FilterDialog::edit()
+{
+ FilterEditDialog dlg( this );
+
+ uint pos = mFilterListBox->currentItem();
+
+ dlg.setFilter( mFilterList[ pos ] );
+
+ if ( dlg.exec() ) {
+ mFilterList.remove( mFilterList.at( pos ) );
+ mFilterList.insert( mFilterList.at( pos ), dlg.filter() );
+ }
+
+ refresh();
+
+ mFilterListBox->setCurrentItem( pos );
+}
+
+void FilterDialog::remove()
+{
+ mFilterList.remove( mFilterList.at( mFilterListBox->currentItem() ) );
+
+ selectionChanged( 0 );
+
+ refresh();
+}
+
+void FilterDialog::refresh()
+{
+ mFilterListBox->clear();
+
+ Filter::List::Iterator iter;
+ for ( iter = mFilterList.begin(); iter != mFilterList.end(); ++iter )
+ mFilterListBox->insertItem( (*iter).name() );
+}
+
+void FilterDialog::selectionChanged( QListBoxItem *item )
+{
+ bool state = ( item != 0 );
+
+ mEditButton->setEnabled( state );
+ mRemoveButton->setEnabled( state );
+}
+
+void FilterDialog::initGUI()
+{
+#ifndef KAB_EMBEDDED
+ resize( 330, 200 );
+#else //KAB_EMBEDDED
+ resize( KMIN(KGlobal::getDesktopWidth()-10, 330), KMIN(KGlobal::getDesktopHeight()-50, 200));
+#endif //KAB_EMBEDDED
+
+ QWidget *page = plainPage();
+
+ QGridLayout *topLayout = new QGridLayout( page, 1, 2, 0, spacingHint() );
+
+ mFilterListBox = new KListBox( page );
+ topLayout->addWidget( mFilterListBox, 0, 0 );
+ connect( mFilterListBox, SIGNAL( selectionChanged( QListBoxItem * ) ),
+ SLOT( selectionChanged( QListBoxItem * ) ) );
+ connect( mFilterListBox, SIGNAL( doubleClicked ( QListBoxItem * ) ),
+ SLOT( edit() ) );
+
+ KButtonBox *buttonBox = new KButtonBox( page, Vertical );
+ buttonBox->addButton( i18n( "&Add..." ), this, SLOT( add() ) );
+ mEditButton = buttonBox->addButton( i18n( "&Edit..." ), this, SLOT( edit() ) );
+ mEditButton->setEnabled( false );
+ mRemoveButton = buttonBox->addButton( i18n( "&Remove" ), this, SLOT( remove() ) );
+ mRemoveButton->setEnabled( false );
+
+ buttonBox->layout();
+ topLayout->addWidget( buttonBox, 0, 1 );
+}
+
+#ifndef KAB_EMBEDDED
+#include "filtereditdialog.moc"
+#endif //KAB_EMBEDDED
diff --git a/kaddressbook/filtereditdialog.h b/kaddressbook/filtereditdialog.h
new file mode 100644
index 0000000..4dd75e4
--- a/dev/null
+++ b/kaddressbook/filtereditdialog.h
@@ -0,0 +1,104 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+/*
+Enhanced Version of the file for platform independent KDE tools.
+Copyright (c) 2004 Ulf Schenk
+
+$Id$
+*/
+
+#ifndef FILTEREDITDIALOG_H
+#define FILTEREDITDIALOG_H
+
+class QButtonGroup;
+class QString;
+class QToolButton;
+class QWidget;
+class QListBoxItem;
+
+class KLineEdit;
+class KListBox;
+class KListView;
+
+#include <kdialogbase.h>
+
+#include "filter.h"
+
+class FilterDialog : public KDialogBase
+{
+ Q_OBJECT
+
+ public:
+ FilterDialog( QWidget *parent, const char *name = 0 );
+ ~FilterDialog();
+
+ void setFilters( const Filter::List &list );
+ Filter::List filters() const;
+
+ protected slots:
+ void add();
+ void edit();
+ void remove();
+ void selectionChanged( QListBoxItem* );
+
+ private:
+ void initGUI();
+ void refresh();
+
+ Filter::List mFilterList;
+ Filter::List mInternalFilterList;
+
+ KListBox *mFilterListBox;
+ QPushButton *mAddButton;
+ QPushButton *mEditButton;
+ QPushButton *mRemoveButton;
+};
+
+class FilterEditDialog : public KDialogBase
+{
+ Q_OBJECT
+ public:
+ FilterEditDialog( QWidget *parent, const char *name = 0 );
+ ~FilterEditDialog();
+
+ void setFilter( const Filter &filter );
+ Filter filter();
+
+ protected slots:
+ void filterNameTextChanged( const QString& );
+ void slotHelp();
+
+ private:
+ void initGUI();
+
+ Filter mFilter;
+
+ KLineEdit *mNameEdit;
+ KListView *mCategoriesView;
+ QButtonGroup *mMatchRuleGroup;
+ QPushButton *mEditButton;
+ QPushButton *mRemoveButton;
+};
+
+#endif
diff --git a/kaddressbook/geowidget.cpp b/kaddressbook/geowidget.cpp
new file mode 100644
index 0000000..13cd084
--- a/dev/null
+++ b/kaddressbook/geowidget.cpp
@@ -0,0 +1,629 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include <kabc/geo.h>
+
+#ifndef KAB_EMBEDDED
+#include <kaccelmanager.h>
+#else //KAB_EMBEDDED
+
+#include <qtextstream.h>
+#include <kglobal.h>
+#endif //KAB_EMBEDDED
+
+#include <knuminput.h>
+#include <kcombobox.h>
+#include <kdebug.h>
+#include <kiconloader.h>
+#include <klocale.h>
+#include <kstandarddirs.h>
+
+#include <qcheckbox.h>
+#include <qfile.h>
+#include <qapplication.h>
+#include <qgroupbox.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qlistbox.h>
+#include <qpainter.h>
+#include <qpixmap.h>
+#include <qpushbutton.h>
+#include <qregexp.h>
+#include <qstring.h>
+#include <stdlib.h>
+
+#include "geowidget.h"
+
+GeoWidget::GeoWidget( QWidget *parent, const char *name )
+ : QWidget( parent, name )
+{
+ QLabel *label = 0;
+
+ QGridLayout *topLayout = new QGridLayout( this, 4, 3 );
+ topLayout->setMargin( KDialog::marginHint() );
+ topLayout->setSpacing( KDialog::spacingHint() );
+
+ label = new QLabel( this );
+//US ambiguous call to loadIcon. Add an additional parameter
+//US label->setPixmap( KGlobal::iconLoader()->loadIcon( "package_network", KIcon::Desktop ) );
+ label->setPixmap( KGlobal::iconLoader()->loadIcon( "package_network", KIcon::Desktop, 0 ) );
+ label->setAlignment( Qt::AlignTop );
+ topLayout->addMultiCellWidget( label, 0, 3, 0, 0 );
+ label->setAlignment( AlignCenter );
+ mGeoIsValid = new QCheckBox( i18n( "Use geo data" ), this );
+ topLayout->addMultiCellWidget( mGeoIsValid, 0, 0, 1, 2 );
+
+ label = new QLabel( i18n( "Latitude:" ), this );
+ topLayout->addWidget( label, 1, 1 );
+
+ mLatitudeBox = new KDoubleSpinBox( -90, 90, 1, 0, 6, this );
+ mLatitudeBox->setEnabled( false );
+ mLatitudeBox->setSuffix( "" );
+ topLayout->addWidget( mLatitudeBox, 1, 2 );
+ label->setBuddy( mLatitudeBox );
+
+ label = new QLabel( i18n( "Longitude:" ), this );
+ topLayout->addWidget( label, 2, 1 );
+
+ mLongitudeBox = new KDoubleSpinBox( -180, 180, 1, 0, 6, this );
+ mLongitudeBox->setEnabled( false );
+ mLongitudeBox->setSuffix( "" );
+ topLayout->addWidget( mLongitudeBox, 2, 2 );
+ label->setBuddy( mLongitudeBox );
+
+ mExtendedButton = new QPushButton( i18n( "Edit Geo Data..." ), this );
+ mExtendedButton->setEnabled( false );
+ topLayout->addMultiCellWidget( mExtendedButton, 3, 3, 1, 2 );
+
+ connect( mLatitudeBox, SIGNAL( valueChanged( double ) ),
+ SIGNAL( changed() ) );
+ connect( mLongitudeBox, SIGNAL( valueChanged( double ) ),
+ SIGNAL( changed() ) );
+ connect( mExtendedButton, SIGNAL( clicked() ),
+ SLOT( editGeoData() ) );
+
+ connect( mGeoIsValid, SIGNAL( toggled( bool ) ),
+ mLatitudeBox, SLOT( setEnabled( bool ) ) );
+ connect( mGeoIsValid, SIGNAL( toggled( bool ) ),
+ mLongitudeBox, SLOT( setEnabled( bool ) ) );
+ connect( mGeoIsValid, SIGNAL( toggled( bool ) ),
+ mExtendedButton, SLOT( setEnabled( bool ) ) );
+ connect( mGeoIsValid, SIGNAL( toggled( bool ) ),
+ SIGNAL( changed() ) );
+
+#ifndef KAB_EMBEDDED
+ KAcceleratorManager::manage( this );
+#endif //KAB_EMBEDDED
+}
+
+GeoWidget::~GeoWidget()
+{
+}
+
+void GeoWidget::setGeo( const KABC::Geo &geo )
+{
+ if ( geo.isValid() ) {
+ mGeoIsValid->setChecked( true );
+ mLatitudeBox->setValue( geo.latitude() );
+ mLongitudeBox->setValue( geo.longitude() );
+ } else
+ mGeoIsValid->setChecked( false );
+}
+
+KABC::Geo GeoWidget::geo() const
+{
+ KABC::Geo geo;
+
+ if ( mGeoIsValid->isChecked() ) {
+ geo.setLatitude( mLatitudeBox->value() );
+ geo.setLongitude( mLongitudeBox->value() );
+ } else {
+ geo.setLatitude( 91 );
+ geo.setLongitude( 181 );
+ }
+
+ return geo;
+}
+
+void GeoWidget::editGeoData()
+{
+ GeoDialog dlg( this );
+
+ dlg.setLatitude( mLatitudeBox->value() );
+ dlg.setLongitude( mLongitudeBox->value() );
+
+ if ( dlg.exec() ) {
+ mLatitudeBox->setValue( dlg.latitude() );
+ mLongitudeBox->setValue( dlg.longitude() );
+
+ emit changed();
+ }
+}
+
+
+
+GeoDialog::GeoDialog( QWidget *parent, const char *name )
+ : KDialogBase( Plain, i18n( "Geo Data Input" ), Ok | Cancel, Ok,
+ parent, name, true, true ),
+ mUpdateSexagesimalInput( true )
+{
+ QFrame *page = plainPage();
+
+ QGridLayout *topLayout = new QGridLayout( page, 1, 1, marginHintSmall(),
+ spacingHint() );
+ //topLayout->setRowStretch( 1, 1 );
+
+ mMapWidget = new GeoMapWidget( page );
+ mCityCombo = new KComboBox( page );
+ QGroupBox *sexagesimalGroup = new QGroupBox( 0, Vertical, i18n( "Sexagesimal" ), page );
+ QGridLayout *sexagesimalLayout = new QGridLayout( sexagesimalGroup->layout(),
+ 2, 5, spacingHint() );
+ QLabel *label;
+ if ( QApplication::desktop()->width() < 320 ) {
+ label = new QLabel( i18n( "La." ), sexagesimalGroup );
+ sexagesimalLayout->setSpacing ( spacingHintSmall() );
+ sexagesimalLayout->setMargin ( marginHintSmall() );
+ topLayout->setMargin ( 0 );
+ mCityCombo->setMaximumWidth( 220 );
+ sexagesimalGroup->setMaximumWidth( 220 );
+ }
+ else
+ label = new QLabel( i18n( "Latitude:" ), sexagesimalGroup );
+ sexagesimalLayout->addWidget( label, 0, 0 );
+
+ int maxWid = 60;
+ if ( QApplication::desktop()->width() < 320 )
+ maxWid = 40;
+ mLatDegrees = new QSpinBox( 0, 90, 1, sexagesimalGroup );
+ mLatDegrees->setSuffix( "" );
+ mLatDegrees->setWrapping( false );
+ sexagesimalLayout->addWidget( mLatDegrees, 0, 1 );
+ mLatDegrees->setMaximumWidth( maxWid );
+
+ mLatMinutes = new QSpinBox( 0, 59, 1, sexagesimalGroup );
+ mLatMinutes->setSuffix( "'" );
+ sexagesimalLayout->addWidget( mLatMinutes, 0, 2 );
+ mLatMinutes->setMaximumWidth( maxWid );
+
+ mLatSeconds = new QSpinBox( 0, 59, 1, sexagesimalGroup );
+ mLatSeconds->setSuffix( "\"" );
+ sexagesimalLayout->addWidget( mLatSeconds, 0, 3 );
+ mLatSeconds->setMaximumWidth( maxWid );
+
+ mLatDirection = new KComboBox( sexagesimalGroup );
+ mLatDirection->insertItem( i18n( "North" ) );
+ mLatDirection->insertItem( i18n( "South" ) );
+ sexagesimalLayout->addWidget( mLatDirection, 0, 4 );
+
+
+ if ( QApplication::desktop()->width() < 320 )
+ label = new QLabel( i18n( "Lo." ), sexagesimalGroup );
+ else
+ label = new QLabel( i18n( "Longitude:" ), sexagesimalGroup );
+
+
+ sexagesimalLayout->addWidget( label, 1, 0 );
+
+ mLongDegrees = new QSpinBox( 0, 180, 1, sexagesimalGroup );
+ mLongDegrees->setSuffix( "" );
+ sexagesimalLayout->addWidget( mLongDegrees, 1, 1 );
+ mLongDegrees->setMaximumWidth( maxWid );
+
+ mLongMinutes = new QSpinBox( 0, 59, 1, sexagesimalGroup );
+ mLongMinutes->setSuffix( "'" );
+ sexagesimalLayout->addWidget( mLongMinutes, 1, 2 );
+ mLongMinutes->setMaximumWidth( maxWid );
+
+ mLongSeconds = new QSpinBox( 0, 59, 1, sexagesimalGroup );
+ mLongSeconds->setSuffix( "\"" );
+ sexagesimalLayout->addWidget( mLongSeconds, 1, 3 );
+ mLongSeconds->setMaximumWidth( maxWid );
+
+ mLongDirection = new KComboBox( sexagesimalGroup );
+ mLongDirection->insertItem( i18n( "East" ) );
+ mLongDirection->insertItem( i18n( "West" ) );
+ sexagesimalLayout->addWidget( mLongDirection, 1, 4 );
+ if ( true /*QApplication::desktop()->width() < 640*/ ) {
+
+ topLayout->addWidget( mMapWidget, 0, 0 );
+ topLayout->addWidget( mCityCombo, 1, 0 );
+ topLayout->addWidget( sexagesimalGroup, 2, 0 );
+
+ } else {
+ topLayout->addMultiCellWidget( mMapWidget, 0, 1, 0, 0 );
+ topLayout->addWidget( mCityCombo, 0, 1 );
+ topLayout->addWidget( sexagesimalGroup, 1, 1 );
+ }
+
+ loadCityList();
+
+ connect( mMapWidget, SIGNAL( changed() ),
+ SLOT( geoMapChanged() ) );
+ connect( mCityCombo, SIGNAL( activated( int ) ),
+ SLOT( cityInputChanged() ) );
+ connect( mLatDegrees, SIGNAL( valueChanged( int ) ),
+ SLOT( sexagesimalInputChanged() ) );
+ connect( mLatMinutes, SIGNAL( valueChanged( int ) ),
+ SLOT( sexagesimalInputChanged() ) );
+ connect( mLatSeconds, SIGNAL( valueChanged( int ) ),
+ SLOT( sexagesimalInputChanged() ) );
+ connect( mLatDirection, SIGNAL( activated( int ) ),
+ SLOT( sexagesimalInputChanged() ) );
+ connect( mLongDegrees, SIGNAL( valueChanged( int ) ),
+ SLOT( sexagesimalInputChanged() ) );
+ connect( mLongMinutes, SIGNAL( valueChanged( int ) ),
+ SLOT( sexagesimalInputChanged() ) );
+ connect( mLongSeconds, SIGNAL( valueChanged( int ) ),
+ SLOT( sexagesimalInputChanged() ) );
+ connect( mLongDirection, SIGNAL( activated( int ) ),
+ SLOT( sexagesimalInputChanged() ) );
+ mLongitude = 0.0;
+ mLatitude = 0.0;
+#ifndef DESKTOP_VERSION
+ showMaximized();
+#endif
+}
+
+GeoDialog::~GeoDialog()
+{
+}
+
+void GeoDialog::setLatitude( double latitude )
+{
+ mLatitude = latitude;
+ updateInputs();
+}
+
+double GeoDialog::latitude() const
+{
+ return mLatitude;
+}
+
+void GeoDialog::setLongitude( double longitude )
+{
+ mLongitude = longitude;
+ updateInputs();
+}
+
+double GeoDialog::longitude() const
+{
+ return mLongitude;
+}
+
+void GeoDialog::sexagesimalInputChanged()
+{
+ mLatitude = (double)( mLatDegrees->value() + (double)mLatMinutes->value() /
+ 60 + (double)mLatSeconds->value() / 3600 );
+
+ mLatitude *= ( mLatDirection->currentItem() == 1 ? -1 : 1 );
+
+ mLongitude = (double)( mLongDegrees->value() + (double)mLongMinutes->value() /
+ 60 + (double)mLongSeconds->value() / 3600 );
+
+ mLongitude *= ( mLongDirection->currentItem() == 1 ? -1 : 1 );
+
+ mUpdateSexagesimalInput = false;
+
+ updateInputs();
+}
+
+void GeoDialog::geoMapChanged()
+{
+ mLatitude = mMapWidget->latitude();
+ mLongitude = mMapWidget->longitude();
+
+ updateInputs();
+}
+
+void GeoDialog::cityInputChanged()
+{
+ if ( mCityCombo->currentItem() != 0 ) {
+ GeoData data = mGeoDataMap[ mCityCombo->currentText() ];
+ mLatitude = data.latitude;
+ mLongitude = data.longitude;
+ } else
+ mLatitude = mLongitude = 0;
+
+ updateInputs();
+}
+
+void GeoDialog::updateInputs()
+{
+ // hmm, doesn't look nice, but there is no better way AFAIK
+ mCityCombo->blockSignals( true );
+ mLatDegrees->blockSignals( true );
+ mLatMinutes->blockSignals( true );
+ mLatSeconds->blockSignals( true );
+ mLatDirection->blockSignals( true );
+ mLongDegrees->blockSignals( true );
+ mLongMinutes->blockSignals( true );
+ mLongSeconds->blockSignals( true );
+ mLongDirection->blockSignals( true );
+
+ mMapWidget->setLatitude( mLatitude );
+ mMapWidget->setLongitude( mLongitude );
+ mMapWidget->update();
+
+ if ( mUpdateSexagesimalInput ) {
+ int degrees, minutes, seconds;
+ double latitude = mLatitude;
+ double longitude = mLongitude;
+
+ latitude *= ( mLatitude < 0 ? -1 : 1 );
+ longitude *= ( mLongitude < 0 ? -1 : 1 );
+
+ degrees = (int)( latitude * 1 );
+ minutes = (int)( ( latitude - degrees ) * 60 );
+ seconds = (int)( (double)( (double)latitude - (double)degrees - ( (double)minutes / (double)60 ) ) * (double)3600 );
+
+ mLatDegrees->setValue( degrees );
+ mLatMinutes->setValue( minutes );
+ mLatSeconds->setValue( seconds );
+
+ mLatDirection->setCurrentItem( mLatitude < 0 ? 1 : 0 );
+
+ degrees = (int)( longitude * 1 );
+ minutes = (int)( ( longitude - degrees ) * 60 );
+ seconds = (int)( (double)( longitude - (double)degrees - ( (double)minutes / 60 ) ) * 3600 );
+
+ mLongDegrees->setValue( degrees );
+ mLongMinutes->setValue( minutes );
+ mLongSeconds->setValue( seconds );
+ mLongDirection->setCurrentItem( mLongitude < 0 ? 1 : 0 );
+ }
+ mUpdateSexagesimalInput = true;
+
+ int pos = nearestCity( mLongitude, mLatitude );
+ if ( pos != -1 )
+ mCityCombo->setCurrentItem( pos + 1 );
+ else
+ mCityCombo->setCurrentItem( 0 );
+
+ mCityCombo->blockSignals( false );
+ mLatDegrees->blockSignals( false );
+ mLatMinutes->blockSignals( false );
+ mLatSeconds->blockSignals( false );
+ mLatDirection->blockSignals( false );
+ mLongDegrees->blockSignals( false );
+ mLongMinutes->blockSignals( false );
+ mLongSeconds->blockSignals( false );
+ mLongDirection->blockSignals( false );
+}
+
+void GeoDialog::loadCityList()
+{
+ mCityCombo->clear();
+ mGeoDataMap.clear();
+
+ QString fileName ;
+#ifdef DESKTOP_VERSION
+#ifndef _WIN32_
+ fileName = qApp->applicationDirPath () + "/kdepim/kaddressbook/zone.tab";
+#else
+ fileName = qApp->applicationDirPath () + "\\kdepim\\kaddressbook\\zone.tab";
+#endif
+#else
+ fileName = getenv("QPEDIR");
+ fileName += "/pics/kdepim/kaddressbook/zone.tab";
+#endif
+
+ QFile file( fileName);
+
+ if ( file.open( IO_ReadOnly ) ) {
+ QTextStream s( &file );
+
+ QString line, country;
+ QRegExp coord( "[+-]\\d+[+-]\\d+" );
+ QRegExp name( "[^\\s]+/[^\\s]+" );
+ int posc, posn, pos;
+
+ while ( !s.eof() ) {
+ line = s.readLine().stripWhiteSpace();
+ if ( line.isEmpty() || line[ 0 ] == '#' )
+ continue;
+
+ country = line.left( 2 );
+ QString c, n;
+#ifdef DESKTOP_VERSION
+ posc = coord.search( line, 0 );
+#else
+ posc = coord.find( line, 0 );
+#endif
+ // if ( pos >= 0 )
+ //c = line.mid( pos, coord.matchedLength() );
+
+#ifdef DESKTOP_VERSION
+ posn = name.search(line, posc);
+#else
+ posn = name.find(line, posc);
+#endif
+ if ( posn > 0 ) {
+ c = line.mid( posc, posn-posc ).stripWhiteSpace();
+ //qDebug("*%s* ", c.latin1());
+ int nend = line.find(" ", posn );
+ if ( nend < 0 )
+ nend = line.length();
+ n = line.mid( posn, nend-posn).stripWhiteSpace();
+ //n.replace( '_', " " );
+ }
+
+ if ( !c.isEmpty() && !n.isEmpty() ) {
+ pos = c.find( "+", 1 );
+ if ( pos < 0 )
+ pos = c.find( "-", 1 );
+ if ( pos > 0 ) {
+ GeoData data;
+ data.latitude = calculateCoordinate( c.left( pos ) );
+ data.longitude = calculateCoordinate( c.mid( pos ) );
+ data.country = country;
+
+ mGeoDataMap.insert( n, data );
+ }
+ }
+ }
+//US I have no mGeoDataMap.keys().
+//US QStringList items( mGeoDataMap.keys() );
+ QStringList items;
+
+ QMap<QString, GeoData>::ConstIterator it;
+ for( it = mGeoDataMap.begin(); it != mGeoDataMap.end(); ++it )
+ items << it.key().latin1();
+
+ items.prepend( i18n( "Undefined" ) );
+ mCityCombo->insertStringList( items );
+
+ file.close();
+ }
+}
+
+double GeoDialog::calculateCoordinate( const QString &coordinate )
+{
+ int neg;
+ int d = 0, m = 0, s = 0;
+ QString str = coordinate;
+
+ neg = str.left( 1 ) == "-";
+ str.remove( 0, 1 );
+
+ switch ( str.length() ) {
+ case 4:
+ d = str.left( 2 ).toInt();
+ m = str.mid( 2 ).toInt();
+ break;
+ case 5:
+ d = str.left( 3 ).toInt();
+ m = str.mid( 3 ).toInt();
+ break;
+ case 6:
+ d = str.left( 2 ).toInt();
+ m = str.mid( 2, 2 ).toInt();
+ s = str.right( 2 ).toInt();
+ break;
+ case 7:
+ d = str.left( 3 ).toInt();
+ m = str.mid( 3, 2 ).toInt();
+ s = str.right( 2 ).toInt();
+ break;
+ default:
+ break;
+ }
+
+ if ( neg )
+ return - ( d + m / 60.0 + s / 3600.0 );
+ else
+ return d + m / 60.0 + s / 3600.0;
+}
+
+int GeoDialog::nearestCity( double x, double y )
+{
+ QMap<QString, GeoData>::Iterator it;
+ int pos = 0;
+ for ( it = mGeoDataMap.begin(); it != mGeoDataMap.end(); ++it, pos++ ) {
+ double dist = ( (*it).longitude - x ) * ( (*it).longitude - x ) +
+ ( (*it).latitude - y ) * ( (*it).latitude - y );
+ if ( dist < 1.5 )
+ return pos;
+ }
+
+ return -1;
+}
+
+
+GeoMapWidget::GeoMapWidget( QWidget *parent, const char *name )
+ : QWidget( parent, name ), mLatitude( 0 ), mLongitude( 0 )
+{
+ setBackgroundMode( NoBackground );
+
+ setFixedSize( 240, 120 );
+
+ update();
+}
+
+GeoMapWidget::~GeoMapWidget()
+{
+}
+
+void GeoMapWidget::setLatitude( double latitude )
+{
+ mLatitude = latitude;
+}
+
+double GeoMapWidget::latitude()const
+{
+ return mLatitude;
+}
+
+void GeoMapWidget::setLongitude( double longitude )
+{
+ mLongitude = longitude;
+}
+
+double GeoMapWidget::longitude()const
+{
+ return mLongitude;
+}
+
+void GeoMapWidget::mousePressEvent( QMouseEvent *event )
+{
+ double latMid = height() / 2;
+ double longMid = width() / 2;
+
+ double latOffset = latMid - event->y();
+ double longOffset = event->x() - longMid;
+
+ mLatitude = ( latOffset * 90 ) / latMid;
+ mLongitude = ( longOffset * 180 ) / longMid;
+
+ emit changed();
+}
+
+void GeoMapWidget::paintEvent( QPaintEvent* )
+{
+ uint w = width();
+ uint h = height();
+
+ QPixmap world = KGlobal::iconLoader()->loadIcon( "world", KIcon::Desktop, 0 );
+
+ QPainter p;
+ p.begin( &world, this );
+
+ p.setPen( QColor( 255, 0, 0 ) );
+ p.setBrush( QColor( 255, 0, 0 ) );
+
+ double latMid = h / 2;
+ double longMid = w / 2;
+
+ double latOffset = ( mLatitude * latMid ) / 90;
+ double longOffset = ( mLongitude * longMid ) / 180;
+
+ int x = (int)(longMid + longOffset);
+ int y = (int)(latMid - latOffset);
+ p.drawEllipse( x, y, 4, 4 );
+
+ p.end();
+ bitBlt( this, 0, 0, &world );
+}
+
+#ifndef KAB_EMBEDDED
+#include "geowidget.moc"
+#endif //KAB_EMBEDDED
diff --git a/kaddressbook/geowidget.h b/kaddressbook/geowidget.h
new file mode 100644
index 0000000..3d39691
--- a/dev/null
+++ b/kaddressbook/geowidget.h
@@ -0,0 +1,155 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef GEOWIDGET_H
+#define GEOWIDGET_H
+
+#include <qmap.h>
+
+#include <qwidget.h>
+#include <kdialogbase.h>
+
+namespace KABC {
+class Geo;
+}
+
+class GeoMapWidget;
+
+class KComboBox;
+class KDoubleSpinBox;
+
+class QCheckBox;
+class QLabel;
+class QSpinBox;
+class QPushButton;
+
+typedef struct {
+ double latitude;
+ double longitude;
+ QString country;
+} GeoData;
+
+class GeoWidget : public QWidget
+{
+ Q_OBJECT
+
+ public:
+ GeoWidget( QWidget *parent, const char *name = 0 );
+ ~GeoWidget();
+
+ /**
+ Sets the geo object.
+ */
+ void setGeo( const KABC::Geo &geo );
+
+ /**
+ Returns a geo object.
+ */
+ KABC::Geo geo() const;
+
+ signals:
+ void changed();
+
+ private slots:
+ void editGeoData();
+
+ private:
+ KDoubleSpinBox *mLatitudeBox;
+ KDoubleSpinBox *mLongitudeBox;
+
+ QCheckBox *mGeoIsValid;
+ QPushButton *mExtendedButton;
+};
+
+class GeoDialog : public KDialogBase
+{
+ Q_OBJECT
+
+ public:
+ GeoDialog( QWidget *parent, const char *name = 0 );
+ ~GeoDialog();
+
+ void setLatitude( double latitude );
+ double latitude() const;
+
+ void setLongitude( double longitude );
+ double longitude() const;
+
+ private slots:
+ void updateInputs();
+
+ void sexagesimalInputChanged();
+ void geoMapChanged();
+ void cityInputChanged();
+
+ private:
+ void loadCityList();
+ double calculateCoordinate( const QString& );
+ int nearestCity( double, double );
+
+ GeoMapWidget *mMapWidget;
+ KComboBox *mCityCombo;
+
+ QSpinBox *mLatDegrees;
+ QSpinBox *mLatMinutes;
+ QSpinBox *mLatSeconds;
+ KComboBox *mLatDirection;
+
+ QSpinBox *mLongDegrees;
+ QSpinBox *mLongMinutes;
+ QSpinBox *mLongSeconds;
+ KComboBox *mLongDirection;
+
+ double mLatitude;
+ double mLongitude;
+ QMap<QString, GeoData> mGeoDataMap;
+ bool mUpdateSexagesimalInput;
+};
+
+class GeoMapWidget : public QWidget
+{
+ Q_OBJECT
+
+ public:
+ GeoMapWidget( QWidget *parent, const char *name = 0 );
+ ~GeoMapWidget();
+
+ void setLatitude( double latitude );
+ double latitude()const;
+
+ void setLongitude( double longitude );
+ double longitude()const;
+
+ signals:
+ void changed();
+
+ protected:
+ virtual void mousePressEvent( QMouseEvent* );
+ virtual void paintEvent( QPaintEvent* );
+
+ private:
+ double mLatitude;
+ double mLongitude;
+};
+
+#endif
diff --git a/kaddressbook/imagewidget.cpp b/kaddressbook/imagewidget.cpp
new file mode 100644
index 0000000..49d456b
--- a/dev/null
+++ b/kaddressbook/imagewidget.cpp
@@ -0,0 +1,299 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include <kabc/picture.h>
+
+#ifndef KAB_EMBEDDED
+#include <kaccelmanager.h>
+#include <kio/netaccess.h>
+#include <kimageio.h>
+#endif //KAB_EMBEDDED
+
+#include <kdebug.h>
+#include <kdialog.h>
+#include <kiconloader.h>
+#include <klocale.h>
+#include <kurlrequester.h>
+#include <kurl.h>
+
+#include <qcheckbox.h>
+#include <qgroupbox.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qpixmap.h>
+#include <qapplication.h>
+
+#include "imagewidget.h"
+
+ImageWidget::ImageWidget( QWidget *parent, const char *name )
+ : QWidget( parent, name )
+{
+ QGridLayout *topLayout = new QGridLayout( this, 2, 1, KDialog::marginHint(),
+ KDialog::spacingHint() );
+
+ QGroupBox *photoBox = new QGroupBox( 0, Qt::Vertical, i18n( "Photo" ), this );
+ QGridLayout *boxLayout = new QGridLayout( photoBox->layout(), 3, 2,
+ KDialog::spacingHint() );
+ boxLayout->setRowStretch( 2, 1 );
+
+ mPhotoLabel = new QLabel( photoBox );
+ int fac = 9;
+ if ( QApplication::desktop()->width() > 320 )
+ fac = 6;
+ mPhotoLabel->setFixedSize( 50*9/fac, 70*9/fac );
+ mPhotoLabel->setScaledContents( true );
+ mPhotoLabel->setFrameStyle( QFrame::Panel | QFrame::Sunken );
+ boxLayout->addMultiCellWidget( mPhotoLabel, 0, 2, 0, 0 );
+
+ mPhotoUrl = new KURLRequester( photoBox );
+#ifndef KAB_EMBEDDED
+ mPhotoUrl->setFilter( KImageIO::pattern() );
+#else //KAB_EMBEDDED
+//US qDebug("ImageWidget::ImageWidget KImageIO not defined. Does this harm ???");
+#endif //KAB_EMBEDDED
+
+
+ boxLayout->addWidget( mPhotoUrl, 0, 1 );
+
+ mUsePhotoUrl = new QCheckBox( i18n( "Store as URL" ), photoBox );
+ mUsePhotoUrl->setEnabled( false );
+ boxLayout->addWidget( mUsePhotoUrl, 1, 1 );
+
+ topLayout->addWidget( photoBox, 0, 0 );
+
+ QGroupBox *logoBox = new QGroupBox( 0, Qt::Vertical, i18n( "Logo" ), this );
+ boxLayout = new QGridLayout( logoBox->layout(), 3, 2, KDialog::spacingHint() );
+ boxLayout->setRowStretch( 2, 1 );
+
+ mLogoLabel = new QLabel( logoBox );
+ mLogoLabel->setFixedSize( 50*9/fac, 70*9/fac );
+ mLogoLabel->setScaledContents( true );
+ mLogoLabel->setFrameStyle( QFrame::Panel | QFrame::Sunken );
+ boxLayout->addMultiCellWidget( mLogoLabel, 0, 2, 0, 0 );
+
+ mLogoUrl = new KURLRequester( logoBox );
+#ifndef KAB_EMBEDDED
+ mLogoUrl->setFilter( KImageIO::pattern() );
+#else //KAB_EMBEDDED
+//US qDebug("ImageWidget::ImageWidget KImageIO not defined 2");
+#endif //KAB_EMBEDDED
+ boxLayout->addWidget( mLogoUrl, 0, 1 );
+
+ mUseLogoUrl = new QCheckBox( i18n( "Store as URL" ), logoBox );
+ mUseLogoUrl->setEnabled( false );
+ boxLayout->addWidget( mUseLogoUrl, 1, 1 );
+
+ topLayout->addWidget( logoBox, 1, 0 );
+
+ connect( mPhotoUrl, SIGNAL( textChanged( const QString& ) ),
+ SIGNAL( changed() ) );
+ connect( mPhotoUrl, SIGNAL( urlSelected( const QString& ) ),
+ SLOT( loadPhoto() ) );
+ connect( mPhotoUrl, SIGNAL( urlSelected( const QString& ) ),
+ SIGNAL( changed() ) );
+ connect( mPhotoUrl, SIGNAL( urlSelected( const QString& ) ),
+ SLOT( updateGUI() ) );
+ connect( mUsePhotoUrl, SIGNAL( toggled( bool ) ),
+ SIGNAL( changed() ) );
+
+ connect( mLogoUrl, SIGNAL( textChanged( const QString& ) ),
+ SIGNAL( changed() ) );
+ connect( mLogoUrl, SIGNAL( urlSelected( const QString& ) ),
+ SLOT( loadLogo() ) );
+ connect( mLogoUrl, SIGNAL( urlSelected( const QString& ) ),
+ SIGNAL( changed() ) );
+ connect( mLogoUrl, SIGNAL( urlSelected( const QString& ) ),
+ SLOT( updateGUI() ) );
+ connect( mUseLogoUrl, SIGNAL( toggled( bool ) ),
+ SIGNAL( changed() ) );
+
+#ifndef KAB_EMBEDDED
+ KAcceleratorManager::manage( this );
+#endif //KAB_EMBEDDED
+
+#ifndef DESKTOP_VERSION
+ mUsePhotoUrl->setChecked( true );
+ mUseLogoUrl->setChecked( true );
+#endif
+}
+
+ImageWidget::~ImageWidget()
+{
+}
+
+void ImageWidget::setPhoto( const KABC::Picture &photo )
+{
+ bool blocked = signalsBlocked();
+ blockSignals( true );
+
+ if ( photo.isIntern() ) {
+//US
+//US mPhotoLabel->setPixmap( photo.data() );
+ if (photo.data().isNull() != true)
+ {
+ QPixmap pm;
+ pm.convertFromImage(photo.data());
+
+ mPhotoLabel->setPixmap( pm );
+ }
+
+ mUsePhotoUrl->setChecked( false );
+ } else {
+ mPhotoUrl->setURL( photo.url() );
+ if ( !photo.url().isEmpty() )
+ mUsePhotoUrl->setChecked( true );
+ loadPhoto();
+ }
+
+ blockSignals( blocked );
+}
+
+KABC::Picture ImageWidget::photo() const
+{
+ KABC::Picture photo;
+
+ if ( mUsePhotoUrl->isChecked() )
+ photo.setUrl( mPhotoUrl->url() );
+ else {
+ QPixmap *px = mPhotoLabel->pixmap();
+ if ( px ) {
+#ifndef KAB_EMBEDDED
+ if ( px->height() > px->width() )
+ photo.setData( px->convertToImage().scaleHeight( 140 ) );
+ else
+ photo.setData( px->convertToImage().scaleWidth( 100 ) );
+#else //KAB_EMBEDDED
+//US add teh nullcheck
+ if (px->isNull() != true )
+ photo.setData( px->convertToImage() );
+#endif //KAB_EMBEDDED
+
+ photo.setType( "PNG" );
+ }
+ }
+
+ return photo;
+}
+
+void ImageWidget::setLogo( const KABC::Picture &logo )
+{
+ bool blocked = signalsBlocked();
+ blockSignals( true );
+
+ if ( logo.isIntern() ) {
+//US
+//US mLogoLabel->setPixmap( logo.data() );
+ if (logo.data().isNull() != true)
+ {
+ QPixmap pm;
+ pm.convertFromImage(logo.data());
+ mLogoLabel->setPixmap( pm );
+ }
+ mUseLogoUrl->setChecked( false );
+ } else {
+ mLogoUrl->setURL( logo.url() );
+ if ( !logo.url().isEmpty() )
+ mUseLogoUrl->setChecked( true );
+ loadLogo();
+ }
+
+ blockSignals( blocked );
+}
+
+KABC::Picture ImageWidget::logo() const
+{
+ KABC::Picture logo;
+
+ if ( mUseLogoUrl->isChecked() )
+ logo.setUrl( mLogoUrl->url() );
+ else {
+ QPixmap *px = mLogoLabel->pixmap();
+ if ( px ) {
+#ifndef KAB_EMBEDDED
+ if ( px->height() > px->width() )
+ logo.setData( px->convertToImage().scaleHeight( 140 ) );
+ else
+ logo.setData( px->convertToImage().scaleWidth( 100 ) );
+#else //KAB_EMBEDDED
+ logo.setData( px->convertToImage() );
+#endif //KAB_EMBEDDED
+
+ logo.setType( "PNG" );
+
+ }
+ }
+
+ return logo;
+}
+
+void ImageWidget::loadPhoto()
+{
+ mPhotoLabel->setPixmap( loadPixmap( mPhotoUrl->url() ) );
+}
+
+void ImageWidget::loadLogo()
+{
+ mLogoLabel->setPixmap( loadPixmap( mLogoUrl->url() ) );
+}
+
+void ImageWidget::updateGUI()
+{
+ KURLRequester *ptr = (KURLRequester*)sender();
+
+#ifdef DESKTOP_VERSION
+ if ( ptr == mPhotoUrl )
+ mUsePhotoUrl->setEnabled( true );
+ else if ( ptr == mLogoUrl )
+ mUseLogoUrl->setEnabled( true );
+#endif
+}
+
+QPixmap ImageWidget::loadPixmap( const KURL &url )
+{
+ QString tempFile;
+ QPixmap pixmap;
+
+ if ( url.isEmpty() )
+ return pixmap;
+
+ if ( url.isLocalFile() )
+ pixmap = QPixmap( url.path() );
+ else
+ {
+#ifndef KAB_EMBEDDED
+ if ( KIO::NetAccess::download( url, tempFile ) ) {
+ pixmap = QPixmap( tempFile );
+ KIO::NetAccess::removeTempFile( tempFile );
+ }
+#else //KAB_EMBEDDED
+ qDebug("ImageWidget::loadPixmap : only local pixmaps are allowed");
+#endif //KAB_EMBEDDED
+
+ }
+
+ return pixmap;
+}
+
+#ifndef KAB_EMBEDDED
+#include "imagewidget.moc"
+#endif //KAB_EMBEDDED
diff --git a/kaddressbook/imagewidget.h b/kaddressbook/imagewidget.h
new file mode 100644
index 0000000..b3ca0bd
--- a/dev/null
+++ b/kaddressbook/imagewidget.h
@@ -0,0 +1,86 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef IMAGEWIDGET_H
+#define IMAGEWIDGET_H
+
+#include <qwidget.h>
+
+#include <kabc/picture.h>
+#include <kdialogbase.h>
+
+class KURL;
+class KURLRequester;
+
+class QCheckBox;
+class QLabel;
+
+class ImageWidget : public QWidget
+{
+ Q_OBJECT
+
+ public:
+ ImageWidget( QWidget *parent, const char *name = 0 );
+ ~ImageWidget();
+
+ /**
+ Sets the photo object.
+ */
+ void setPhoto( const KABC::Picture &photo );
+
+ /**
+ Returns a photo object.
+ */
+ KABC::Picture photo() const;
+
+ /**
+ Sets the logo object.
+ */
+ void setLogo( const KABC::Picture &photo );
+
+ /**
+ Returns a logo object.
+ */
+ KABC::Picture logo() const;
+
+ signals:
+ void changed();
+
+ private slots:
+ void loadPhoto();
+ void loadLogo();
+ void updateGUI();
+
+ private:
+ QPixmap loadPixmap( const KURL &url );
+
+ KURLRequester *mPhotoUrl;
+ KURLRequester *mLogoUrl;
+
+ QCheckBox *mUsePhotoUrl;
+ QCheckBox *mUseLogoUrl;
+ QLabel *mPhotoLabel;
+ QLabel *mLogoLabel;
+};
+
+#endif
diff --git a/kaddressbook/incsearchwidget.cpp b/kaddressbook/incsearchwidget.cpp
new file mode 100644
index 0000000..94c37e7
--- a/dev/null
+++ b/kaddressbook/incsearchwidget.cpp
@@ -0,0 +1,147 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qtooltip.h>
+#include <qcombobox.h>
+
+#include <kdialog.h>
+#include <klineedit.h>
+#include <klocale.h>
+#include <kglobal.h>
+
+#include "incsearchwidget.h"
+
+IncSearchWidget::IncSearchWidget( QWidget *parent, const char *name )
+ : QWidget( parent, name )
+{
+#ifndef KAB_EMBEDDED
+//US setCaption( i18n( "Incremental Search" ) );
+#endif //KAB_EMBEDDED
+
+ QHBoxLayout *layout = new QHBoxLayout( this, 2, KDialog::spacingHint() );
+
+#ifdef DESKTOP_VERSION
+ QLabel *label = new QLabel( i18n( "Search:" ), this );
+ label->setAlignment( QLabel::AlignVCenter | QLabel::AlignRight );
+ layout->addWidget( label );
+#endif //KAB_EMBEDDED
+
+ mSearchText = new KLineEdit( this );
+ layout->addWidget( mSearchText );
+// #ifdef KAB_EMBEDDED
+// if (KGlobal::getOrientation() == KGlobal::Portrait)
+// mSearchText->setMaximumWidth(30);
+// #endif //KAB_EMBEDDED
+
+
+ mFieldCombo = new QComboBox( false, this );
+ layout->addWidget( mFieldCombo );
+ mFieldCombo->setMaximumHeight( 34 );
+ QToolTip::add( mFieldCombo, i18n( "Select Incremental Search Field" ) );
+
+// #ifndef KAB_EMBEDDED
+// resize( QSize(420, 50).expandedTo( sizeHint() ) );
+// #else //KAB_EMBEDDED
+// resize( QSize(30, 10).expandedTo( sizeHint() ) );
+// #endif //KAB_EMBEDDED
+
+ connect( mSearchText, SIGNAL( textChanged( const QString& ) ),
+ SLOT( announceDoSearch() ) );
+ connect( mSearchText, SIGNAL( returnPressed() ),
+ SLOT( announceDoSearch() ) );
+ connect( mFieldCombo, SIGNAL( activated( const QString& ) ),
+ SLOT( announceDoSearch() ) );
+ connect( mFieldCombo, SIGNAL( activated( const QString& ) ),
+ SLOT( announceFieldChanged() ) );
+
+ setFocusProxy( mSearchText );
+}
+
+IncSearchWidget::~IncSearchWidget()
+{
+
+}
+
+void IncSearchWidget::announceDoSearch()
+{
+ emit doSearch( mSearchText->text() );
+}
+
+void IncSearchWidget::announceFieldChanged()
+{
+ emit fieldChanged();
+}
+
+void IncSearchWidget::setFields( const KABC::Field::List &list )
+{
+
+ mFieldCombo->clear();
+ mFieldCombo->insertItem( i18n( "All Fields" ) );
+ QFontMetrics fm ( mFieldCombo->font() );
+ int wid = fm.width(i18n( "All Fields" ) );
+ int max = wid;
+
+ KABC::Field::List::ConstIterator it;
+ for ( it = list.begin(); it != list.end(); ++it ) {
+ mFieldCombo->insertItem( (*it)->label() );
+ // wid = fm.width((*it)->label() );
+ //if ( wid > max )
+ // max = wid;
+ }
+
+ mFieldList = list;
+
+ announceDoSearch();
+ announceFieldChanged();
+ mFieldCombo->setMaximumWidth( wid+60 );
+}
+
+KABC::Field::List IncSearchWidget::fields() const
+{
+ return mFieldList;
+}
+
+KABC::Field *IncSearchWidget::currentField()const
+{
+ if ( mFieldCombo->currentItem() == -1 || mFieldCombo->currentItem() == 0 )
+ return 0; // for error or 'use all fields'
+ else
+ return mFieldList[ mFieldCombo->currentItem() - 1 ];
+}
+
+void IncSearchWidget::setCurrentItem( int pos )
+{
+ mFieldCombo->setCurrentItem( pos );
+ announceFieldChanged();
+}
+
+int IncSearchWidget::currentItem() const
+{
+
+ return mFieldCombo->currentItem();
+}
+#ifndef KAB_EMBEDDED
+#include "incsearchwidget.moc"
+#endif //KAB_EMBEDDED
diff --git a/kaddressbook/incsearchwidget.h b/kaddressbook/incsearchwidget.h
new file mode 100644
index 0000000..09fb8ac
--- a/dev/null
+++ b/kaddressbook/incsearchwidget.h
@@ -0,0 +1,73 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef INCSEARCHWIDGET_H
+#define INCSEARCHWIDGET_H
+
+#include <qwidget.h>
+
+#include <kabc/field.h>
+
+class QComboBox;
+class KLineEdit;
+
+class IncSearchWidget : public QWidget
+{
+ Q_OBJECT
+
+ public:
+ IncSearchWidget( QWidget *parent, const char *name = 0 );
+ ~IncSearchWidget();
+
+ void setFields( const KABC::Field::List &list );
+ KABC::Field::List fields() const;
+
+ KABC::Field *currentField() const;
+
+ void setCurrentItem( int pos );
+ int currentItem() const;
+
+ signals:
+ /**
+ This signal is emmited whenever the text in the input
+ widget is changed. You can get the sorting field by
+ @ref currentField.
+ */
+ void doSearch( const QString& text );
+
+ /**
+ This signal is emmited whenever the search field changes.
+ */
+ void fieldChanged();
+
+ private slots:
+ void announceDoSearch();
+ void announceFieldChanged();
+
+ private:
+ QComboBox* mFieldCombo;
+ KLineEdit* mSearchText;
+ KABC::Field::List mFieldList;
+};
+
+#endif
diff --git a/kaddressbook/jumpbuttonbar.cpp b/kaddressbook/jumpbuttonbar.cpp
new file mode 100644
index 0000000..ee5b44e
--- a/dev/null
+++ b/kaddressbook/jumpbuttonbar.cpp
@@ -0,0 +1,232 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include <qevent.h>
+#include <qlayout.h>
+#include <qpushbutton.h>
+#include <qstring.h>
+#include <qtl.h>
+#include <qapplication.h>
+
+#include <kabc/addressbook.h>
+#include <kabc/field.h>
+#include <kdebug.h>
+#include <klocale.h>
+
+#include "kabcore.h"
+
+#include "jumpbuttonbar.h"
+
+class JumpButton : public QPushButton
+{
+ public:
+ JumpButton( const QString &text, QWidget *parent,
+ const QString &character );
+
+ void setCharacter( const QString &character );
+ QString character() const;
+
+ private:
+ QString mCharacter;
+};
+
+JumpButton::JumpButton( const QString &text, QWidget *parent,
+ const QString &character )
+ : QPushButton( text, parent )
+{
+ mCharacter = character;
+}
+
+void JumpButton::setCharacter( const QString &character )
+{
+ mCharacter = character;
+ setText(mCharacter.upper() );
+}
+
+QString JumpButton::character() const
+{
+ return mCharacter;
+}
+
+JumpButtonBar::JumpButtonBar( KABCore *core, QWidget *parent, const char *name )
+ : QWidget( parent, name ), mCore( core )
+{
+ if ( QApplication::desktop()->width() < 480 )
+
+ mButtonLayout = new QGridLayout( this, 2, 14 );
+ else
+ mButtonLayout = new QGridLayout( this, 1, 28 );
+ mButtonLayout->setAlignment( Qt::AlignTop );
+
+ recreateButtons();
+}
+
+JumpButtonBar::~JumpButtonBar()
+{
+}
+
+QSizePolicy JumpButtonBar::sizePolicy() const
+{
+#ifndef KAB_EMBEDDED
+ return QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Minimum,
+ QSizePolicy::Vertically );
+#else //KAB_EMBEDDED
+ return QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Minimum);
+#endif //KAB_EMBEDDED
+}
+
+void JumpButtonBar::letterClicked()
+{
+ JumpButton *button = (JumpButton*)sender();
+ QString character = button->character();
+ if ( !character.isNull() )
+ emit jumpToLetter( character );
+}
+
+void JumpButtonBar::recreateButtons()
+{
+ // the easiest way to remove all buttons ;)
+ //mButtons.setAutoDelete( true );
+ //mButtons.clear();
+ //mButtons.setAutoDelete( false );
+ mCharacters.clear();
+
+ QString character;
+
+ KABC::AddressBook *ab = mCore->addressBook();
+ KABC::AddressBook::Iterator it;
+ KABC::Field *field = mCore->currentSearchField();
+ if ( field ) {
+ setEnabled( true );
+ } else {
+ setEnabled( false );
+ return;
+ }
+ for ( it = ab->begin(); it != ab->end(); ++it ) {
+ if ( !field->value( *it ).isEmpty() )
+ character = field->value( *it )[ 0 ].lower();
+ if ( !character.isEmpty() && !mCharacters.contains( character ) )
+ mCharacters.append( character );
+ }
+ if ( mCharacters.count() == 0 ) {
+ setEnabled( false );
+ return;
+ }
+
+ int maxRows = mCharacters.count() / 2; // we use 2 columns
+ if ( mCharacters.count() % 2 )
+ maxRows++;
+ int fixwid = 20;
+ sortListLocaleAware( mCharacters );
+ bool skip2 = false;
+ int skipcount = 0;
+ int maxHei = 25;
+ if ( QApplication::desktop()->width() < 480 && mCharacters.count() > 13) {
+ skipcount = mCharacters.count()-13;
+ maxHei = (QApplication::desktop()->height()-65)/13;
+ }
+ else {
+ fixwid = 30;
+ if ( mCharacters.count() > 20 )
+ skipcount = mCharacters.count()- 20;
+ maxHei = (QApplication::desktop()->height()-120)/(mCharacters.count()-skipcount);
+
+ }
+ maxRows = 28;
+ bool skipcurrent = false;
+ bool state = isUpdatesEnabled();
+ setUpdatesEnabled( false );
+ //qDebug("cc %d ",mCharacters.count() );
+ JumpButton *button;
+ int row = 0, col = 0;
+ JumpButton* cur = mButtons.first();
+ for ( uint i = 0; i < mCharacters.count(); ++i ) {
+ if ( skipcount > 0 && skipcurrent ) {
+ --skipcount;
+ } else {
+ if ( cur ) {
+ button = cur ;
+ cur = mButtons.next();
+ button->setCharacter(mCharacters[ i ]);
+ } else {
+ button = new JumpButton( mCharacters[ i ].upper(), this, mCharacters[ i ] );
+ button->setFixedWidth( fixwid );
+ mButtons.append( button );
+ connect( button, SIGNAL( clicked() ), this, SLOT( letterClicked() ) );
+ mButtonLayout->addWidget( button, row, col );
+ }
+ button->setMaximumHeight( maxHei );
+ button->show();
+
+ if ( col == maxRows ) {
+ row = 0;
+ col++;
+ } else
+ row++;
+ }
+
+ skipcurrent = !skipcurrent;
+ }
+ while ( cur ) {
+ cur->hide();
+ cur = mButtons.next();
+ }
+
+ mButtonLayout->activate();
+ setUpdatesEnabled( state );
+ update();
+}
+
+void JumpButtonBar::sortListLocaleAware( QStringList &list )
+{
+ QStringList::Iterator beginIt = list.begin();
+ QStringList::Iterator endIt = list.end();
+
+ --endIt;
+ if ( beginIt == endIt ) // don't need sorting
+ return;
+
+ QStringList::Iterator walkBackIt = endIt;
+ while ( beginIt != endIt ) {
+ QStringList::Iterator j1 = list.begin();
+ QStringList::Iterator j2 = j1;
+ ++j2;
+ while ( j1 != walkBackIt ) {
+#ifndef KAB_EMBEDDED
+ if ( QString::localeAwareCompare( *j2, *j1 ) < 0 )
+#else //KAB_EMBEDDED
+ if ( QString::compare( *j2, *j1 ) < 0 )
+#endif //KAB_EMBEDDED
+ qSwap( *j1, *j2 );
+
+ ++j1;
+ ++j2;
+ }
+ ++beginIt;
+ --walkBackIt;
+ }
+}
+
+#ifndef KAB_EMBEDDED
+#include "jumpbuttonbar.moc"
+#endif //KAB_EMBEDDED
diff --git a/kaddressbook/jumpbuttonbar.h b/kaddressbook/jumpbuttonbar.h
new file mode 100644
index 0000000..d534f2b
--- a/dev/null
+++ b/kaddressbook/jumpbuttonbar.h
@@ -0,0 +1,84 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef JUMPBUTTONBAR_H
+#define JUMPBUTTONBAR_H
+
+#include <qsizepolicy.h>
+#include <qwidget.h>
+#include <qptrlist.h>
+#include <qstringlist.h>
+
+class QChar;
+class QGridLayout;
+class QResizeEvent;
+class QPushButton;
+class JumpButton;
+
+namespace KABC {
+class Field;
+}
+
+class KABCore;
+
+/**
+ Used to draw the jump button bar on the right of the view.
+ */
+class JumpButtonBar : public QWidget
+{
+ Q_OBJECT
+
+ public:
+ JumpButtonBar( KABCore *core, QWidget *parent, const char *name = 0 );
+ ~JumpButtonBar();
+
+ QSizePolicy sizePolicy() const;
+
+ public slots:
+ /**
+ This method removes all buttons from the GUI and recreates them
+ according to the current global search field and the content of
+ the address book.
+ */
+ void recreateButtons();
+
+ signals:
+ /**
+ Emitted whenever a letter is selected by the user.
+ */
+ void jumpToLetter( const QString &character );
+
+ protected slots:
+ void letterClicked();
+
+ private:
+ void sortListLocaleAware( QStringList &list );
+
+ KABCore *mCore;
+
+ QGridLayout *mButtonLayout;
+ QStringList mCharacters;
+ QPtrList<JumpButton> mButtons;
+};
+
+#endif
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
new file mode 100644
index 0000000..3e578bc
--- a/dev/null
+++ b/kaddressbook/kabcore.cpp
@@ -0,0 +1,1571 @@
+/*
+ This file is part of KAddressbook.
+ Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include "kabcore.h"
+
+#include <stdaddressbook.h>
+#include <klocale.h>
+
+#ifndef KAB_EMBEDDED
+#include <qclipboard.h>
+#include <qdir.h>
+#include <qfile.h>
+#include <qapplicaton.h>
+#include <qlayout.h>
+#include <qregexp.h>
+#include <qvbox.h>
+#include <kabc/addresseelist.h>
+#include <kabc/errorhandler.h>
+#include <kabc/resource.h>
+#include <kabc/vcardconverter.h>
+#include <kapplication.h>
+#include <kactionclasses.h>
+#include <kcmultidialog.h>
+#include <kdebug.h>
+#include <kdeversion.h>
+#include <kkeydialog.h>
+#include <kmessagebox.h>
+#include <kprinter.h>
+#include <kprotocolinfo.h>
+#include <kresources/selectdialog.h>
+#include <kstandarddirs.h>
+#include <ktempfile.h>
+#include <kxmlguiclient.h>
+#include <kaboutdata.h>
+#include <libkdepim/categoryselectdialog.h>
+
+#include "addresseeutil.h"
+#include "addresseeeditordialog.h"
+#include "extensionmanager.h"
+#include "kstdaction.h"
+#include "kaddressbookservice.h"
+#include "ldapsearchdialog.h"
+#include "printing/printingwizard.h"
+#else // KAB_EMBEDDED
+
+#include "KDGanttMinimizeSplitter.h"
+#include "kaddressbookmain.h"
+#include "kactioncollection.h"
+#include <qapp.h>
+#include <qmenubar.h>
+//#include <qtoolbar.h>
+#include <qmessagebox.h>
+#include <kdebug.h>
+#include <kiconloader.h> // needed for SmallIcon
+#include <kresources/kcmkresources.h>
+#include <ktoolbar.h>
+
+#include <kcmkabconfig.h>
+
+//US#include <qpe/resource.h> // needed for Resource::loadPixmap
+//#include <qlabel.h>
+#endif // KAB_EMBEDDED
+#include <kcmkabconfig.h>
+
+
+#include <kresources/selectdialog.h>
+#include <kmessagebox.h>
+
+#include <picture.h>
+#include <resource.h>
+
+//US#include <qsplitter.h>
+#include <qvbox.h>
+#include <qlayout.h>
+#include <qclipboard.h>
+
+#include <libkdepim/categoryselectdialog.h>
+
+#include "addresseeutil.h"
+#include "undocmds.h"
+#include "addresseeeditordialog.h"
+#include "viewmanager.h"
+#include "details/detailsviewcontainer.h"
+#include "kabprefs.h"
+#include "xxportmanager.h"
+#include "incsearchwidget.h"
+#include "jumpbuttonbar.h"
+#include "extensionmanager.h"
+#include "addresseeconfig.h"
+#include <kcmultidialog.h>
+
+
+#ifdef KAB_EMBEDDED
+KABCore::KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name )
+ : QWidget( parent, name ), mGUIClient( client ), mViewManager( 0 ),
+ mExtensionManager( 0 ),mConfigureDialog( 0 ),/*US mLdapSearchDialog( 0 ),*/
+ mReadWrite( readWrite ), mModified( false ), mMainWindow(client)
+#else //KAB_EMBEDDED
+KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const char *name )
+ : QWidget( parent, name ), mGUIClient( client ), mViewManager( 0 ),
+ mExtensionManager( 0 ), mConfigureDialog( 0 ), mLdapSearchDialog( 0 ),
+ mReadWrite( readWrite ), mModified( false )
+#endif //KAB_EMBEDDED
+{
+#ifdef KAB_EMBEDDED
+ //US we define here our own global actioncollection.
+ //mActionCollection = new KActionCollection(this);
+#endif //KAB_EMBEDDED
+
+ mIsPart = !parent->inherits( "KAddressBookMain" );
+
+ mAddressBook = KABC::StdAddressBook::self();
+ KABC::StdAddressBook::setAutomaticSave( true );
+
+#ifndef KAB_EMBEDDED
+ mAddressBook->setErrorHandler( new KABC::GUIErrorHandler );
+#endif //KAB_EMBEDDED
+
+ connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook * ) ),
+ SLOT( addressBookChanged() ) );
+
+ mAddressBook->addCustomField( i18n( "Department" ), KABC::Field::Organization,
+ "X-Department", "KADDRESSBOOK" );
+ mAddressBook->addCustomField( i18n( "Profession" ), KABC::Field::Organization,
+ "X-Profession", "KADDRESSBOOK" );
+ mAddressBook->addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization,
+ "X-AssistantsName", "KADDRESSBOOK" );
+ mAddressBook->addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization,
+ "X-ManagersName", "KADDRESSBOOK" );
+ mAddressBook->addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal,
+ "X-SpousesName", "KADDRESSBOOK" );
+ mAddressBook->addCustomField( i18n( "Office" ), KABC::Field::Personal,
+ "X-Office", "KADDRESSBOOK" );
+ mAddressBook->addCustomField( i18n( "IM Address" ), KABC::Field::Personal,
+ "X-IMAddress", "KADDRESSBOOK" );
+ mAddressBook->addCustomField( i18n( "Anniversary" ), KABC::Field::Personal,
+ "X-Anniversary", "KADDRESSBOOK" );
+
+ initGUI();
+
+ mIncSearchWidget->setFocus();
+
+
+ connect( mViewManager, SIGNAL( selected( const QString& ) ),
+ SLOT( setContactSelected( const QString& ) ) );
+ connect( mViewManager, SIGNAL( executed( const QString& ) ),
+ SLOT( editContact( const QString& ) ) );
+ connect( mViewManager, SIGNAL( deleteRequest( ) ),
+ SLOT( deleteContacts( ) ) );
+ connect( mViewManager, SIGNAL( modified() ),
+ SLOT( setModified() ) );
+
+ connect( mExtensionManager, SIGNAL( modified( const KABC::Addressee::List& ) ), this, SLOT( extensionModified( const KABC::Addressee::List& ) ) );
+
+ connect( mXXPortManager, SIGNAL( modified() ),
+ SLOT( setModified() ) );
+
+ connect( mJumpButtonBar, SIGNAL( jumpToLetter( const QString& ) ),
+ SLOT( incrementalSearch( const QString& ) ) );
+ connect( mIncSearchWidget, SIGNAL( fieldChanged() ),
+ mJumpButtonBar, SLOT( recreateButtons() ) );
+
+#ifndef KAB_EMBEDDED
+ connect( mViewManager, SIGNAL( urlDropped( const KURL& ) ),
+ mXXPortManager, SLOT( importVCard( const KURL& ) ) );
+
+ connect( mDetails, SIGNAL( sendEmail( const QString& ) ),
+ SLOT( sendMail( const QString& ) ) );
+ connect( mDetails, SIGNAL( browse( const QString& ) ),
+ SLOT( browse( const QString& ) ) );
+
+ mAddressBookService = new KAddressBookService( this );
+
+#endif //KAB_EMBEDDED
+
+ setModified( false );
+}
+
+KABCore::~KABCore()
+{
+ // save();
+ //saveSettings();
+ //KABPrefs::instance()->writeConfig();
+ delete AddresseeConfig::instance();
+ mAddressBook = 0;
+ KABC::StdAddressBook::close();
+
+#ifdef KAB_EMBEDDED
+ //US we define here our own global actioncollection.
+ // delete mActionCollection;
+#endif //KAB_EMBEDDED
+
+}
+
+void KABCore::restoreSettings()
+{
+ bool state = KABPrefs::instance()->mJumpButtonBarVisible;
+
+ mActionJumpBar->setChecked( state );
+ setJumpButtonBarVisible( state );
+
+ state = KABPrefs::instance()->mDetailsPageVisible;
+
+ mActionDetails->setChecked( state );
+ setDetailsVisible( state );
+ QValueList<int> splitterSize = KABPrefs::instance()->mExtensionsSplitter;
+ if ( splitterSize.count() == 0 ) {
+ splitterSize.append( width() / 2 );
+ splitterSize.append( width() / 2 );
+ }
+ mMiniSplitter->setSizes( splitterSize );
+#ifndef KAB_EMBEDDED
+ QValueList<int> splitterSize = KABPrefs::instance()->mExtensionsSplitter;
+ if ( splitterSize.count() == 0 ) {
+ splitterSize.append( width() / 2 );
+ splitterSize.append( width() / 2 );
+ }
+ mExtensionBarSplitter->setSizes( splitterSize );
+
+ splitterSize = KABPrefs::instance()->mDetailsSplitter;
+ if ( splitterSize.count() == 0 ) {
+ splitterSize.append( height() / 2 );
+ splitterSize.append( height() / 2 );
+ }
+ mDetailsSplitter->setSizes( splitterSize );
+
+ mExtensionManager->restoreSettings();
+
+#endif //KAB_EMBEDDED
+
+ mIncSearchWidget->setCurrentItem( KABPrefs::instance()->mCurrentIncSearchField );
+
+ mViewManager->restoreSettings();
+ mExtensionManager->restoreSettings();
+}
+
+void KABCore::saveSettings()
+{
+ KABPrefs::instance()->mJumpButtonBarVisible = mActionJumpBar->isChecked();
+ KABPrefs::instance()->mExtensionsSplitter = mMiniSplitter->sizes();
+ KABPrefs::instance()->mDetailsPageVisible = mActionDetails->isChecked();
+
+#ifndef KAB_EMBEDDED
+
+ KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes();
+ KABPrefs::instance()->mDetailsSplitter = mDetailsSplitter->sizes();
+#endif //KAB_EMBEDDED
+ mExtensionManager->saveSettings();
+ mViewManager->saveSettings();
+
+ KABPrefs::instance()->mCurrentIncSearchField = mIncSearchWidget->currentItem();
+
+}
+
+KABC::AddressBook *KABCore::addressBook() const
+{
+ return mAddressBook;
+}
+
+KConfig *KABCore::config()
+{
+#ifndef KAB_EMBEDDED
+ return KABPrefs::instance()->config();
+#else //KAB_EMBEDDED
+ return KABPrefs::instance()->getConfig();
+#endif //KAB_EMBEDDED
+}
+
+KActionCollection *KABCore::actionCollection() const
+{
+ return mGUIClient->actionCollection();
+}
+
+KABC::Field *KABCore::currentSearchField() const
+{
+ if (mIncSearchWidget)
+ return mIncSearchWidget->currentField();
+ else
+ return 0;
+}
+
+QStringList KABCore::selectedUIDs() const
+{
+ return mViewManager->selectedUids();
+}
+
+KABC::Resource *KABCore::requestResource( QWidget *parent )
+{
+ QPtrList<KABC::Resource> kabcResources = addressBook()->resources();
+
+ QPtrList<KRES::Resource> kresResources;
+ QPtrListIterator<KABC::Resource> resIt( kabcResources );
+ KABC::Resource *resource;
+ while ( ( resource = resIt.current() ) != 0 ) {
+ ++resIt;
+ if ( !resource->readOnly() ) {
+ KRES::Resource *res = static_cast<KRES::Resource*>( resource );
+ if ( res )
+ kresResources.append( res );
+ }
+ }
+
+ KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, parent );
+ return static_cast<KABC::Resource*>( res );
+}
+
+#ifndef KAB_EMBEDDED
+KAboutData *KABCore::createAboutData()
+#else //KAB_EMBEDDED
+void KABCore::createAboutData()
+#endif //KAB_EMBEDDED
+{
+#ifndef KAB_EMBEDDED
+ KAboutData *about = new KAboutData( "kaddressbook", I18N_NOOP( "KAddressBook" ),
+ "3.1", I18N_NOOP( "The KDE Address Book" ),
+ KAboutData::License_GPL_V2,
+ I18N_NOOP( "(c) 1997-2003, The KDE PIM Team" ) );
+ about->addAuthor( "Tobias Koenig", I18N_NOOP( "Current maintainer " ), "tokoe@kde.org" );
+ about->addAuthor( "Don Sanders", I18N_NOOP( "Original author " ) );
+ about->addAuthor( "Cornelius Schumacher",
+ I18N_NOOP( "Co-maintainer, libkabc port, CSV import/export " ),
+ "schumacher@kde.org" );
+ about->addAuthor( "Mike Pilone", I18N_NOOP( "GUI and framework redesign " ),
+ "mpilone@slac.com" );
+ about->addAuthor( "Greg Stern", I18N_NOOP( "DCOP interface" ) );
+ about->addAuthor( "Mark Westcott", I18N_NOOP( "Contact pinning" ) );
+ about->addAuthor( "Michel Boyer de la Giroday", I18N_NOOP( "LDAP Lookup\n" ),
+ "michel@klaralvdalens-datakonsult.se" );
+ about->addAuthor( "Steffen Hansen", I18N_NOOP( "LDAP Lookup " ),
+ "hansen@kde.org" );
+
+ return about;
+#endif //KAB_EMBEDDED
+
+ QString version;
+#include <../version>
+ QMessageBox::about( this, "About KAddressbook/Pi",
+ "KAddressbook/Platform-independent\n"
+ "(KA/Pi) " +version + " - " +
+#ifdef DESKTOP_VERSION
+ "Desktop Edition\n"
+#else
+ "PDA-Edition\n"
+ "for: Zaurus 5500 / 7x0 / 8x0\n"
+#endif
+
+ "(c) 2004 Ulf Schenk\n"
+ "(c) 1997-2003, The KDE PIM Team\n"
+ "Tobias Koenig Current maintainer tokoe@kde.org\n"
+ "Don Sanders Original author\n"
+ "Cornelius Schumacher Co-maintainer schumacher@kde.org\n"
+ "Mike Pilone GUI and framework redesign mpilone@slac.com\n"
+ "Greg Stern DCOP interface\n"
+ "Mark Westcot Contact pinning\n"
+ "Michel Boyer de la Giroday LDAP Lookup\n" "michel@klaralvdalens-datakonsult.se\n"
+ "Steffen Hansen LDAP Lookup hansen@kde.org\n" );
+}
+
+void KABCore::setContactSelected( const QString &uid )
+{
+ KABC::Addressee addr = mAddressBook->findByUid( uid );
+ if ( !mDetails->isHidden() )
+ mDetails->setAddressee( addr );
+
+ if ( !addr.isEmpty() ) {
+ emit contactSelected( addr.formattedName() );
+ KABC::Picture pic = addr.photo();
+ if ( pic.isIntern() ) {
+//US emit contactSelected( pic.data() );
+//US instead use:
+ QPixmap px;
+ if (pic.data().isNull() != true)
+ {
+ px.convertFromImage(pic.data());
+ }
+
+ emit contactSelected( px );
+ }
+ }
+
+
+ mExtensionManager->setSelectionChanged();
+
+ // update the actions
+ bool selected = !uid.isEmpty();
+
+ if ( mReadWrite ) {
+ mActionCut->setEnabled( selected );
+ mActionPaste->setEnabled( selected );
+ }
+
+ mActionCopy->setEnabled( selected );
+ mActionDelete->setEnabled( selected );
+ mActionEditAddressee->setEnabled( selected );
+ mActionMail->setEnabled( selected );
+ mActionMailVCard->setEnabled( selected );
+ mActionWhoAmI->setEnabled( selected );
+ mActionCategories->setEnabled( selected );
+}
+
+void KABCore::sendMail()
+{
+#ifndef KAB_EMBEDDED
+ sendMail( mViewManager->selectedEmails().join( ", " ) );
+#else //KAB_EMBEDDED
+ qDebug("KABCore::sendMail() ust be fixed");
+#endif //KAB_EMBEDDED
+}
+
+void KABCore::sendMail( const QString& email )
+{
+#ifndef KAB_EMBEDDED
+ kapp->invokeMailer( email, "" );
+#else //KAB_EMBEDDED
+ qDebug("KABCore::sendMail(const QString& email) ust be fixed");
+#endif //KAB_EMBEDDED
+}
+
+void KABCore::mailVCard()
+{
+#ifndef KAB_EMBEDDED
+ QStringList uids = mViewManager->selectedUids();
+ if ( !uids.isEmpty() )
+ mailVCard( uids );
+#else //KAB_EMBEDDED
+ qDebug("KABCore::mailVCard() must be fixed");
+#endif //KAB_EMBEDDED
+}
+
+void KABCore::mailVCard( const QStringList& uids )
+{
+#ifndef KAB_EMBEDDED
+ QStringList urls;
+
+ // Create a temp dir, so that we can put the files in it with proper names
+ KTempFile tempDir;
+ if ( tempDir.status() != 0 ) {
+ kdWarning() << strerror( tempDir.status() ) << endl;
+ return;
+ }
+
+ QString dirName = tempDir.name();
+ tempDir.unlink();
+ QDir().mkdir( dirName, true );
+
+ for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) {
+ KABC::Addressee a = mAddressBook->findByUid( *it );
+
+ if ( a.isEmpty() )
+ continue;
+
+ QString name = a.givenName() + "_" + a.familyName() + ".vcf";
+
+ QString fileName = dirName + "/" + name;
+
+ QFile outFile(fileName);
+ if ( outFile.open(IO_WriteOnly) ) { // file opened successfully
+ KABC::VCardConverter converter;
+ QString vcard;
+
+ converter.addresseeToVCard( a, vcard );
+
+ QTextStream t( &outFile ); // use a text stream
+ t.setEncoding( QTextStream::UnicodeUTF8 );
+ t << vcard;
+
+ outFile.close();
+
+ urls.append( fileName );
+ }
+ }
+
+ kapp->invokeMailer( QString::null, QString::null, QString::null,
+ QString::null, // subject
+ QString::null, // body
+ QString::null,
+ urls ); // attachments
+#else //KAB_EMBEDDED
+ qDebug("KABCore::mailVCard( must be fixed");
+#endif //KAB_EMBEDDED
+
+}
+
+void KABCore::browse( const QString& url )
+{
+#ifndef KAB_EMBEDDED
+ kapp->invokeBrowser( url );
+#else //KAB_EMBEDDED
+ qDebug("KABCore::browse must be fixed");
+#endif //KAB_EMBEDDED
+}
+
+void KABCore::selectAllContacts()
+{
+ mViewManager->setSelected( QString::null, true );
+}
+
+void KABCore::deleteContacts()
+{
+ QStringList uidList = mViewManager->selectedUids();
+ deleteContacts( uidList );
+}
+
+void KABCore::deleteContacts( const QStringList &uids )
+{
+ if ( uids.count() > 0 ) {
+ PwDeleteCommand *command = new PwDeleteCommand( mAddressBook, uids );
+ UndoStack::instance()->push( command );
+ RedoStack::instance()->clear();
+
+ // now if we deleted anything, refresh
+ setContactSelected( QString::null );
+ setModified( true );
+ }
+}
+
+void KABCore::copyContacts()
+{
+ KABC::Addressee::List addrList = mViewManager->selectedAddressees();
+
+ QString clipText = AddresseeUtil::addresseesToClipboard( addrList );
+
+ kdDebug(5720) << "KABCore::copyContacts: " << clipText << endl;
+
+ QClipboard *cb = QApplication::clipboard();
+ cb->setText( clipText );
+}
+
+void KABCore::cutContacts()
+{
+ QStringList uidList = mViewManager->selectedUids();
+
+//US if ( uidList.size() > 0 ) {
+ if ( uidList.count() > 0 ) {
+ PwCutCommand *command = new PwCutCommand( mAddressBook, uidList );
+ UndoStack::instance()->push( command );
+ RedoStack::instance()->clear();
+
+ setModified( true );
+ }
+}
+
+void KABCore::pasteContacts()
+{
+ QClipboard *cb = QApplication::clipboard();
+
+ KABC::Addressee::List list = AddresseeUtil::clipboardToAddressees( cb->text() );
+
+ pasteContacts( list );
+}
+
+void KABCore::pasteContacts( KABC::Addressee::List &list )
+{
+ KABC::Resource *resource = requestResource( this );
+ KABC::Addressee::List::Iterator it;
+ for ( it = list.begin(); it != list.end(); ++it )
+ (*it).setResource( resource );
+
+ PwPasteCommand *command = new PwPasteCommand( this, list );
+ UndoStack::instance()->push( command );
+ RedoStack::instance()->clear();
+
+ setModified( true );
+}
+
+void KABCore::setWhoAmI()
+{
+ KABC::Addressee::List addrList = mViewManager->selectedAddressees();
+
+ if ( addrList.count() > 1 ) {
+ KMessageBox::sorry( this, i18n( "Please select only one contact." ) );
+ return;
+ }
+
+ QString text( i18n( "<qt>Do you really want to use <b>%1</b> as your new personal contact?</qt>" ) );
+ if ( KMessageBox::questionYesNo( this, text.arg( addrList[ 0 ].assembledName() ) ) == KMessageBox::Yes )
+ static_cast<KABC::StdAddressBook*>( KABC::StdAddressBook::self() )->setWhoAmI( addrList[ 0 ] );
+}
+
+void KABCore::setCategories()
+{
+ KPIM::CategorySelectDialog dlg( KABPrefs::instance(), this, "", true );
+ if ( !dlg.exec() )
+ return;
+
+ bool merge = false;
+ QString msg = i18n( "Merge with existing categories?" );
+ if ( KMessageBox::questionYesNo( this, msg ) == KMessageBox::Yes )
+ merge = true;
+
+ QStringList categories = dlg.selectedCategories();
+
+ QStringList uids = mViewManager->selectedUids();
+ QStringList::Iterator it;
+ for ( it = uids.begin(); it != uids.end(); ++it ) {
+ KABC::Addressee addr = mAddressBook->findByUid( *it );
+ if ( !addr.isEmpty() ) {
+ if ( !merge )
+ addr.setCategories( categories );
+ else {
+ QStringList addrCategories = addr.categories();
+ QStringList::Iterator catIt;
+ for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) {
+ if ( !addrCategories.contains( *catIt ) )
+ addrCategories.append( *catIt );
+ }
+ addr.setCategories( addrCategories );
+ }
+
+ mAddressBook->insertAddressee( addr );
+ }
+ }
+
+ if ( uids.count() > 0 )
+ setModified( true );
+}
+
+void KABCore::setSearchFields( const KABC::Field::List &fields )
+{
+ mIncSearchWidget->setFields( fields );
+}
+
+void KABCore::incrementalSearch( const QString& text )
+{
+ mViewManager->setSelected( QString::null, false );
+
+ if ( !text.isEmpty() ) {
+ KABC::Field *field = mIncSearchWidget->currentField();
+
+ QString pattern = text.lower();
+
+#if KDE_VERSION >= 319
+ KABC::AddresseeList list( mAddressBook->allAddressees() );
+ if ( field ) {
+ list.sortByField( field );
+ KABC::AddresseeList::Iterator it;
+ for ( it = list.begin(); it != list.end(); ++it ) {
+ if ( field->value( *it ).lower().startsWith( pattern ) ) {
+ mViewManager->setSelected( (*it).uid(), true );
+ return;
+ }
+ }
+ } else {
+ KABC::AddresseeList::Iterator it;
+ for ( it = list.begin(); it != list.end(); ++it ) {
+ KABC::Field::List fieldList = mIncSearchWidget->fields();
+ KABC::Field::List::ConstIterator fieldIt;
+ for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) {
+ if ( (*fieldIt)->value( *it ).lower().startsWith( pattern ) ) {
+ mViewManager->setSelected( (*it).uid(), true );
+ return;
+ }
+ }
+ }
+ }
+#else
+ KABC::AddressBook::Iterator it;
+ for ( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) {
+ if ( field ) {
+ if ( field->value( *it ).lower().startsWith( pattern ) ) {
+ mViewManager->setSelected( (*it).uid(), true );
+ return;
+ }
+ } else {
+ KABC::Field::List fieldList = mIncSearchWidget->fields();
+ KABC::Field::List::ConstIterator fieldIt;
+ for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) {
+ if ( (*fieldIt)->value( *it ).lower().startsWith( pattern ) ) {
+ mViewManager->setSelected( (*it).uid(), true );
+ return;
+ }
+ }
+ }
+ }
+#endif
+ }
+}
+
+void KABCore::setModified()
+{
+ setModified( true );
+}
+
+void KABCore::setModifiedWOrefresh()
+{
+ // qDebug("KABCore::setModifiedWOrefresh() ");
+ mModified = true;
+ mActionSave->setEnabled( mModified );
+#ifdef DESKTOP_VERSION
+ mDetails->refreshView();
+#endif
+
+}
+void KABCore::setModified( bool modified )
+{
+ mModified = modified;
+ mActionSave->setEnabled( mModified );
+
+ if ( modified )
+ mJumpButtonBar->recreateButtons();
+
+ mViewManager->refreshView();
+ mDetails->refreshView();
+
+}
+
+bool KABCore::modified() const
+{
+ return mModified;
+}
+
+void KABCore::contactModified( const KABC::Addressee &addr )
+{
+
+ Command *command = 0;
+ QString uid;
+
+ // check if it exists already
+ KABC::Addressee origAddr = mAddressBook->findByUid( addr.uid() );
+ if ( origAddr.isEmpty() )
+ command = new PwNewCommand( mAddressBook, addr );
+ else {
+ command = new PwEditCommand( mAddressBook, origAddr, addr );
+ uid = addr.uid();
+ }
+
+ UndoStack::instance()->push( command );
+ RedoStack::instance()->clear();
+
+ setModified( true );
+}
+
+void KABCore::newContact()
+{
+ AddresseeEditorDialog *dialog = 0;
+
+ QPtrList<KABC::Resource> kabcResources = mAddressBook->resources();
+
+ QPtrList<KRES::Resource> kresResources;
+ QPtrListIterator<KABC::Resource> it( kabcResources );
+ KABC::Resource *resource;
+ while ( ( resource = it.current() ) != 0 ) {
+ ++it;
+ if ( !resource->readOnly() ) {
+ KRES::Resource *res = static_cast<KRES::Resource*>( resource );
+ if ( res )
+ kresResources.append( res );
+ }
+ }
+
+ KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, this );
+ resource = static_cast<KABC::Resource*>( res );
+
+ if ( resource ) {
+ KABC::Addressee addr;
+ addr.setResource( resource );
+ dialog = createAddresseeEditorDialog( this );
+ dialog->setAddressee( addr );
+
+ } else
+ return;
+
+ mEditorDict.insert( dialog->addressee().uid(), dialog );
+
+ dialog->show();
+
+}
+
+void KABCore::addEmail( QString aStr )
+{
+#ifndef KAB_EMBEDDED
+ QString fullName, email;
+
+ KABC::Addressee::parseEmailAddress( aStr, fullName, email );
+
+ // Try to lookup the addressee matching the email address
+ bool found = false;
+ QStringList emailList;
+ KABC::AddressBook::Iterator it;
+ for ( it = mAddressBook->begin(); !found && (it != mAddressBook->end()); ++it ) {
+ emailList = (*it).emails();
+ if ( emailList.contains( email ) > 0 ) {
+ found = true;
+ (*it).setNameFromString( fullName );
+ editContact( (*it).uid() );
+ }
+ }
+
+ if ( !found ) {
+ KABC::Addressee addr;
+ addr.setNameFromString( fullName );
+ addr.insertEmail( email, true );
+
+ mAddressBook->insertAddressee( addr );
+ mViewManager->refreshView( addr.uid() );
+ editContact( addr.uid() );
+ }
+#else //KAB_EMBEDDED
+ qDebug("KABCore::addEmail finsih method");
+#endif //KAB_EMBEDDED
+}
+
+void KABCore::importVCard( const KURL &url, bool showPreview )
+{
+ mXXPortManager->importVCard( url, showPreview );
+}
+
+void KABCore::importVCard( const QString &vCard, bool showPreview )
+{
+ mXXPortManager->importVCard( vCard, showPreview );
+}
+
+//US added a second method without defaultparameter
+void KABCore::editContact2() {
+ editContact( QString::null );
+}
+
+void KABCore::editContact( const QString &uid )
+{
+
+ if ( mExtensionManager->isQuickEditVisible() )
+ return;
+
+ // First, locate the contact entry
+ QString localUID = uid;
+ if ( localUID.isNull() ) {
+ QStringList uidList = mViewManager->selectedUids();
+ if ( uidList.count() > 0 )
+ localUID = *( uidList.at( 0 ) );
+ }
+
+ KABC::Addressee addr = mAddressBook->findByUid( localUID );
+ if ( !addr.isEmpty() ) {
+ AddresseeEditorDialog *dialog = mEditorDict.find( addr.uid() );
+ if ( !dialog ) {
+ dialog = createAddresseeEditorDialog( this );
+
+ mEditorDict.insert( addr.uid(), dialog );
+
+ dialog->setAddressee( addr );
+ }
+
+ dialog->raise();
+ dialog->show();
+ }
+}
+
+void KABCore::save()
+{
+ if ( !mModified )
+ return;
+ QString text = i18n( "There was an error while attempting to save\n the "
+ "address book. Please check that some \nother application is "
+ "not using it. " );
+ statusMessage(i18n("Saving addressbook ... "));
+#ifndef KAB_EMBEDDED
+ KABC::StdAddressBook *b = dynamic_cast<KABC::StdAddressBook*>( mAddressBook );
+ if ( !b || !b->save() ) {
+ KMessageBox::error( this, text, i18n( "Unable to Save" ) );
+ }
+#else //KAB_EMBEDDED
+ KABC::StdAddressBook *b = (KABC::StdAddressBook*)( mAddressBook );
+ if ( !b || !b->save() ) {
+ QMessageBox::critical( this, i18n( "Unable to Save" ), text, i18n("Ok"));
+ }
+#endif //KAB_EMBEDDED
+
+ statusMessage(i18n("Addressbook saved!"));
+ setModified( false );
+}
+
+void KABCore::statusMessage(QString mess , int time )
+{
+ //topLevelWidget()->setCaption( mess );
+ // pending setting timer to revome message
+}
+void KABCore::undo()
+{
+ UndoStack::instance()->undo();
+
+ // Refresh the view
+ mViewManager->refreshView();
+}
+
+void KABCore::redo()
+{
+ RedoStack::instance()->redo();
+
+ // Refresh the view
+ mViewManager->refreshView();
+}
+
+void KABCore::setJumpButtonBarVisible( bool visible )
+{
+ if ( visible )
+ mJumpButtonBar->show();
+ else
+ mJumpButtonBar->hide();
+}
+void KABCore::setDetailsToState()
+{
+ setDetailsVisible( mActionDetails->isChecked() );
+}
+
+void KABCore::setDetailsVisible( bool visible )
+{
+ if ( visible )
+ mDetails->show();
+ else
+ mDetails->hide();
+}
+
+void KABCore::extensionModified( const KABC::Addressee::List &list )
+{
+
+ if ( list.count() != 0 ) {
+ KABC::Addressee::List::ConstIterator it;
+ for ( it = list.begin(); it != list.end(); ++it )
+ mAddressBook->insertAddressee( *it );
+ if ( list.count() > 1 )
+ setModified();
+ else
+ setModifiedWOrefresh();
+ }
+ if ( list.count() == 0 )
+ mViewManager->refreshView();
+ else
+ mViewManager->refreshView( list[ 0 ].uid() );
+
+
+
+}
+
+QString KABCore::getNameByPhone( const QString &phone )
+{
+#ifndef KAB_EMBEDDED
+ QRegExp r( "[/*/-/ ]" );
+ QString localPhone( phone );
+
+ bool found = false;
+ QString ownerName = "";
+ KABC::AddressBook::Iterator iter;
+ KABC::PhoneNumber::List::Iterator phoneIter;
+ KABC::PhoneNumber::List phoneList;
+ for ( iter = mAddressBook->begin(); !found && ( iter != mAddressBook->end() ); ++iter ) {
+ phoneList = (*iter).phoneNumbers();
+ for ( phoneIter = phoneList.begin(); !found && ( phoneIter != phoneList.end() );
+ ++phoneIter) {
+ // Get rid of separator chars so just the numbers are compared.
+ if ( (*phoneIter).number().replace( r, "" ) == localPhone.replace( r, "" ) ) {
+ ownerName = (*iter).formattedName();
+ found = true;
+ }
+ }
+ }
+
+ return ownerName;
+#else //KAB_EMBEDDED
+ qDebug("KABCore::getNameByPhone finsih method");
+ return "";
+#endif //KAB_EMBEDDED
+
+}
+
+void KABCore::openConfigDialog()
+{
+ KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"kabconfigdialog", true );
+ KCMKabConfig* kabcfg = new KCMKabConfig( ConfigureDialog->getNewVBoxPage(i18n( "Addressbook")) , "KCMKabConfig" );
+ ConfigureDialog->addModule(kabcfg );
+ connect( ConfigureDialog, SIGNAL( applyClicked() ),
+ this, SLOT( configurationChanged() ) );
+ connect( ConfigureDialog, SIGNAL( okClicked() ),
+ this, SLOT( configurationChanged() ) );
+ saveSettings();
+ ConfigureDialog->exec();
+ delete ConfigureDialog;
+}
+
+void KABCore::openLDAPDialog()
+{
+#ifndef KAB_EMBEDDED
+ if ( !mLdapSearchDialog ) {
+ mLdapSearchDialog = new LDAPSearchDialog( mAddressBook, this );
+ connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), mViewManager,
+ SLOT( refreshView() ) );
+ connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), this,
+ SLOT( setModified() ) );
+ } else
+ mLdapSearchDialog->restoreSettings();
+
+ if ( mLdapSearchDialog->isOK() )
+ mLdapSearchDialog->exec();
+#else //KAB_EMBEDDED
+ qDebug("KABCore::openLDAPDialog() finsih method");
+#endif //KAB_EMBEDDED
+}
+
+void KABCore::print()
+{
+#ifndef KAB_EMBEDDED
+ KPrinter printer;
+ if ( !printer.setup( this ) )
+ return;
+
+ KABPrinting::PrintingWizard wizard( &printer, mAddressBook,
+ mViewManager->selectedUids(), this );
+
+ wizard.exec();
+#else //KAB_EMBEDDED
+ qDebug("KABCore::print() finsih method");
+#endif //KAB_EMBEDDED
+
+}
+
+
+void KABCore::addGUIClient( KXMLGUIClient *client )
+{
+ if ( mGUIClient )
+ mGUIClient->insertChildClient( client );
+ else
+ KMessageBox::error( this, "no KXMLGUICLient");
+}
+
+
+void KABCore::configurationChanged()
+{
+ mExtensionManager->reconfigure();
+}
+
+void KABCore::addressBookChanged()
+{
+#ifndef KAB_EMBEDDED
+ QDictIterator<AddresseeEditorDialog> it( mEditorDict );
+ while ( it.current() ) {
+ if ( it.current()->dirty() ) {
+ QString text = i18n( "Data has been changed externally. Unsaved "
+ "changes will be lost." );
+ KMessageBox::information( this, text );
+ }
+ it.current()->setAddressee( mAddressBook->findByUid( it.currentKey() ) );
+ ++it;
+ }
+
+ mViewManager->refreshView();
+#else //KAB_EMBEDDED
+ qDebug("KABCore::addressBookChanged() finsih method");
+#endif //KAB_EMBEDDED
+}
+
+AddresseeEditorDialog *KABCore::createAddresseeEditorDialog( QWidget *parent,
+ const char *name )
+{
+ AddresseeEditorDialog *dialog = new AddresseeEditorDialog( this, parent,
+ name ? name : "editorDialog" );
+
+//US
+ dialog->setMaximumSize( 640, 480 );
+ dialog->showMaximized();
+
+ connect( dialog, SIGNAL( contactModified( const KABC::Addressee& ) ),
+ SLOT( contactModified( const KABC::Addressee& ) ) );
+ connect( dialog, SIGNAL( editorDestroyed( const QString& ) ),
+ SLOT( slotEditorDestroyed( const QString& ) ) );
+
+ return dialog;
+}
+
+void KABCore::slotEditorDestroyed( const QString &uid )
+{
+ mEditorDict.remove( uid );
+}
+
+void KABCore::initGUI()
+{
+#ifndef KAB_EMBEDDED
+ QHBoxLayout *topLayout = new QHBoxLayout( this );
+ topLayout->setSpacing( KDialogBase::spacingHint() );
+
+ mExtensionBarSplitter = new QSplitter( this );
+ mExtensionBarSplitter->setOrientation( Qt::Vertical );
+
+ mDetailsSplitter = new QSplitter( mExtensionBarSplitter );
+
+ QVBox *viewSpace = new QVBox( mDetailsSplitter );
+ mIncSearchWidget = new IncSearchWidget( viewSpace );
+ connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ),
+ SLOT( incrementalSearch( const QString& ) ) );
+
+ mViewManager = new ViewManager( this, viewSpace );
+ viewSpace->setStretchFactor( mViewManager, 1 );
+
+ mDetails = new ViewContainer( mDetailsSplitter );
+
+ mJumpButtonBar = new JumpButtonBar( this, this );
+
+ mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter );
+
+ topLayout->addWidget( mExtensionBarSplitter );
+ topLayout->setStretchFactor( mExtensionBarSplitter, 100 );
+ topLayout->addWidget( mJumpButtonBar );
+ topLayout->setStretchFactor( mJumpButtonBar, 1 );
+
+ mXXPortManager = new XXPortManager( this, this );
+
+#else //KAB_EMBEDDED
+ //US initialize viewMenu before settingup viewmanager.
+ // Viewmanager needs this menu to plugin submenues.
+ viewMenu = new QPopupMenu( this );
+ settingsMenu = new QPopupMenu( this );
+ //filterMenu = new QPopupMenu( this );
+ ImportMenu = new QPopupMenu( this );
+ ExportMenu = new QPopupMenu( this );
+
+
+//US since we have no splitter for the embedded system, setup
+// a layout with two frames. One left and one right.
+
+ QBoxLayout *topLayout;
+
+ // = new QHBoxLayout( this );
+// QBoxLayout *topLayout = (QBoxLayout*)layout();
+
+// QWidget *mainBox = new QWidget( this );
+// QBoxLayout * mainBoxLayout = new QHBoxLayout(mainBox);
+
+
+ if ( QApplication::desktop()->width() > 480 ) {
+ topLayout = new QHBoxLayout( this );
+ mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this);
+ mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right );
+ } else {
+
+ topLayout = new QVBoxLayout( this );
+ mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Vertical, this);
+ mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down );
+ }
+
+ topLayout->addWidget(mMiniSplitter );
+ mViewManager = new ViewManager( this, mMiniSplitter );
+ mDetails = new ViewContainer( mMiniSplitter );
+
+
+ mExtensionManager = new ExtensionManager( this, mMiniSplitter );
+
+ //eh->hide();
+ // topLayout->addWidget(mExtensionManager );
+
+
+/*US
+#ifndef KAB_NOSPLITTER
+ QHBoxLayout *topLayout = new QHBoxLayout( this );
+//US topLayout->setSpacing( KDialogBase::spacingHint() );
+ topLayout->setSpacing( 10 );
+
+ mDetailsSplitter = new QSplitter( this );
+
+ QVBox *viewSpace = new QVBox( mDetailsSplitter );
+
+ mViewManager = new ViewManager( this, viewSpace );
+ viewSpace->setStretchFactor( mViewManager, 1 );
+
+ mDetails = new ViewContainer( mDetailsSplitter );
+
+ topLayout->addWidget( mDetailsSplitter );
+ topLayout->setStretchFactor( mDetailsSplitter, 100 );
+#else //KAB_NOSPLITTER
+ QHBoxLayout *topLayout = new QHBoxLayout( this );
+//US topLayout->setSpacing( KDialogBase::spacingHint() );
+ topLayout->setSpacing( 10 );
+
+// mDetailsSplitter = new QSplitter( this );
+
+ QVBox *viewSpace = new QVBox( this );
+
+ mViewManager = new ViewManager( this, viewSpace );
+ viewSpace->setStretchFactor( mViewManager, 1 );
+
+ mDetails = new ViewContainer( this );
+
+ topLayout->addWidget( viewSpace );
+// topLayout->setStretchFactor( mDetailsSplitter, 100 );
+ topLayout->addWidget( mDetails );
+#endif //KAB_NOSPLITTER
+*/
+
+
+#endif //KAB_EMBEDDED
+ initActions();
+
+#ifdef KAB_EMBEDDED
+ addActionsManually();
+ //US make sure the export and import menues are initialized before creating the xxPortManager.
+ mXXPortManager = new XXPortManager( this, this );
+
+ // LR mIncSearchWidget = new IncSearchWidget( mMainWindow->getIconToolBar() );
+ //mMainWindow->toolBar()->insertWidget(-1, 4, mIncSearchWidget);
+ // mActionQuit->plug ( mMainWindow->toolBar());
+ //mIncSearchWidget = new IncSearchWidget( mMainWindow->toolBar() );
+ //mMainWindow->toolBar()->insertWidget(-1, 0, mIncSearchWidget);
+ // mIncSearchWidget->hide();
+ connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ),
+ SLOT( incrementalSearch( const QString& ) ) );
+
+
+ mJumpButtonBar = new JumpButtonBar( this, this );
+
+ topLayout->addWidget( mJumpButtonBar );
+//US topLayout->setStretchFactor( mJumpButtonBar, 10 );
+
+// mMainWindow->getIconToolBar()->raise();
+
+#endif //KAB_EMBEDDED
+
+}
+void KABCore::initActions()
+{
+//US qDebug("KABCore::initActions(): mIsPart %i", mIsPart);
+
+#ifndef KAB_EMBEDDED
+ connect( QApplication::clipboard(), SIGNAL( dataChanged() ),
+ SLOT( clipboardDataChanged() ) );
+#endif //KAB_EMBEDDED
+
+ // file menu
+ if ( mIsPart ) {
+ mActionMail = new KAction( i18n( "&Mail" ), "mail_generic", 0, this,
+ SLOT( sendMail() ), actionCollection(),
+ "kaddressbook_mail" );
+ mActionPrint = new KAction( i18n( "&Print" ), "fileprint", CTRL + Key_P, this,
+ SLOT( print() ), actionCollection(), "kaddressbook_print" );
+
+ } else {
+ mActionMail = KStdAction::mail( this, SLOT( sendMail() ), actionCollection() );
+ mActionPrint = KStdAction::print( this, SLOT( print() ), actionCollection() );
+ }
+
+ mActionSave = new KAction( i18n( "&Save" ), "filesave", CTRL+Key_S, this,
+ SLOT( save() ), actionCollection(), "file_sync" );
+
+ mActionNewContact = new KAction( i18n( "&New Contact..." ), "filenew", CTRL+Key_N, this,
+ SLOT( newContact() ), actionCollection(), "file_new_contact" );
+
+ mActionMailVCard = new KAction(i18n("Mail &vCard..."), "mail_post_to", 0,
+ this, SLOT( mailVCard() ),
+ actionCollection(), "file_mail_vcard");
+
+ mActionEditAddressee = new KAction( i18n( "&Edit Contact..." ), "edit", 0,
+ this, SLOT( editContact2() ),
+ actionCollection(), "file_properties" );
+
+#ifdef KAB_EMBEDDED
+ // mActionQuit = KStdAction::quit( mMainWindow, SLOT( exit() ), actionCollection() );
+ mActionQuit = new KAction( i18n( "&Exit" ), "exit", 0,
+ mMainWindow, SLOT( exit() ),
+ actionCollection(), "quit" );
+#endif //KAB_EMBEDDED
+
+ // edit menu
+ if ( mIsPart ) {
+ mActionCopy = new KAction( i18n( "&Copy" ), "editcopy", CTRL + Key_C, this,
+ SLOT( copyContacts() ), actionCollection(),
+ "kaddressbook_copy" );
+ mActionCut = new KAction( i18n( "Cu&t" ), "editcut", CTRL + Key_X, this,
+ SLOT( cutContacts() ), actionCollection(),
+ "kaddressbook_cut" );
+ mActionPaste = new KAction( i18n( "&Paste" ), "editpaste", CTRL + Key_V, this,
+ SLOT( pasteContacts() ), actionCollection(),
+ "kaddressbook_paste" );
+ mActionSelectAll = new KAction( i18n( "Select &All" ), CTRL + Key_A, this,
+ SLOT( selectAllContacts() ), actionCollection(),
+ "kaddressbook_select_all" );
+ mActionUndo = new KAction( i18n( "&Undo" ), "undo", CTRL + Key_Z, this,
+ SLOT( undo() ), actionCollection(),
+ "kaddressbook_undo" );
+ mActionRedo = new KAction( i18n( "Re&do" ), "redo", CTRL + SHIFT + Key_Z,
+ this, SLOT( redo() ), actionCollection(),
+ "kaddressbook_redo" );
+ } else {
+ mActionCopy = KStdAction::copy( this, SLOT( copyContacts() ), actionCollection() );
+ mActionCut = KStdAction::cut( this, SLOT( cutContacts() ), actionCollection() );
+ mActionPaste = KStdAction::paste( this, SLOT( pasteContacts() ), actionCollection() );
+ mActionSelectAll = KStdAction::selectAll( this, SLOT( selectAllContacts() ), actionCollection() );
+ mActionUndo = KStdAction::undo( this, SLOT( undo() ), actionCollection() );
+ mActionRedo = KStdAction::redo( this, SLOT( redo() ), actionCollection() );
+ }
+
+ mActionDelete = new KAction( i18n( "&Delete Contact" ), "editdelete",
+ Key_Delete, this, SLOT( deleteContacts() ),
+ actionCollection(), "edit_delete" );
+
+ mActionUndo->setEnabled( false );
+ mActionRedo->setEnabled( false );
+
+ // settings menu
+#ifdef KAB_EMBEDDED
+//US special menuentry to configure the addressbook resources. On KDE
+// you do that through the control center !!!
+ mActionConfigResources = new KAction( i18n( "Configure &Resources..." ), "configure_resources", 0, this,
+ SLOT( configureResources() ), actionCollection(),
+ "kaddressbook_configure_resources" );
+#endif //KAB_EMBEDDED
+
+ if ( mIsPart ) {
+ mActionConfigKAddressbook = new KAction( i18n( "&Configure KAddressBook..." ), "configure", 0, this,
+ SLOT( openConfigDialog() ), actionCollection(),
+ "kaddressbook_configure" );
+
+ mActionConfigShortcuts = new KAction( i18n( "Configure S&hortcuts..." ), "configure_shortcuts", 0,
+ this, SLOT( configureKeyBindings() ), actionCollection(),
+ "kaddressbook_configure_shortcuts" );
+#ifdef KAB_EMBEDDED
+ mActionConfigureToolbars = KStdAction::configureToolbars( this, SLOT( mMainWindow->configureToolbars() ), actionCollection() );
+#endif //KAB_EMBEDDED
+
+ } else {
+ mActionConfigKAddressbook = KStdAction::preferences( this, SLOT( openConfigDialog() ), actionCollection() );
+
+ mActionKeyBindings = KStdAction::keyBindings( this, SLOT( configureKeyBindings() ), actionCollection() );
+ }
+
+ mActionJumpBar = new KToggleAction( i18n( "Show Jump Bar" ), 0, 0,
+ actionCollection(), "options_show_jump_bar" );
+ connect( mActionJumpBar, SIGNAL( toggled( bool ) ), SLOT( setJumpButtonBarVisible( bool ) ) );
+
+ mActionDetails = new KToggleAction( i18n( "Show Details" ), 0, 0,
+ actionCollection(), "options_show_details" );
+ connect( mActionDetails, SIGNAL( toggled( bool ) ), SLOT( setDetailsVisible( bool ) ) );
+
+ // misc
+ // only enable LDAP lookup if we can handle the protocol
+#ifndef KAB_EMBEDDED
+ if ( KProtocolInfo::isKnownProtocol( KURL( "ldap://localhost" ) ) ) {
+ new KAction( i18n( "&Lookup Addresses in Directory" ), "find", 0,
+ this, SLOT( openLDAPDialog() ), actionCollection(),
+ "ldap_lookup" );
+ }
+#else //KAB_EMBEDDED
+ //qDebug("KABCore::initActions() LDAP has to be implemented");
+#endif //KAB_EMBEDDED
+
+
+ mActionWhoAmI = new KAction( i18n( "Set Who Am I" ), "personal", 0, this,
+ SLOT( setWhoAmI() ), actionCollection(),
+ "set_personal" );
+
+ mActionCategories = new KAction( i18n( "Set Categories" ), 0, this,
+ SLOT( setCategories() ), actionCollection(),
+ "edit_set_categories" );
+
+#ifdef KAB_EMBEDDED
+
+ mActionAboutKAddressbook = new KAction( i18n( "&About KAddressBook" ), "kaddressbook2", 0,
+ this, SLOT( createAboutData() ), actionCollection(),
+ "kaddressbook_about_data" );
+#endif //KAB_EMBEDDED
+
+ clipboardDataChanged();
+ connect( UndoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) );
+ connect( RedoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) );
+}
+
+//US we need this function, to plug all actions into the correct menues.
+// KDE uses a XML format to plug the actions, but we work her without this overhead.
+void KABCore::addActionsManually()
+{
+//US qDebug("KABCore::initActions(): mIsPart %i", mIsPart);
+
+#ifdef KAB_EMBEDDED
+ QPopupMenu *fileMenu = new QPopupMenu( this );
+ QPopupMenu *editMenu = new QPopupMenu( this );
+ QPopupMenu *helpMenu = new QPopupMenu( this );
+
+ KToolBar* tb = mMainWindow->toolBar();
+
+#ifdef DESKTOP_VERSION
+ QMenuBar* mb = mMainWindow->menuBar();
+
+ //US setup menubar.
+ //Disable the following block if you do not want to have a menubar.
+ mb->insertItem( "&File", fileMenu );
+ mb->insertItem( "&Edit", editMenu );
+ mb->insertItem( "&View", viewMenu );
+ mb->insertItem( "&Settings", settingsMenu );
+ mb->insertItem( "&Help", helpMenu );
+ mIncSearchWidget = new IncSearchWidget( tb );
+ // tb->insertWidget(-1, 0, mIncSearchWidget);
+
+#else
+ //US setup toolbar
+ QMenuBar *menuBarTB = new QMenuBar( tb );
+ QPopupMenu *popupBarTB = new QPopupMenu( this );
+ menuBarTB->insertItem( "ME", popupBarTB);
+ tb->insertWidget(-1, 0, menuBarTB);
+ mIncSearchWidget = new IncSearchWidget( tb );
+
+ tb->enableMoving(false);
+ popupBarTB->insertItem( "&File", fileMenu );
+ popupBarTB->insertItem( "&Edit", editMenu );
+ popupBarTB->insertItem( "&View", viewMenu );
+ popupBarTB->insertItem( "&Settings", settingsMenu );
+ mViewManager->getFilterAction()->plug ( popupBarTB);
+ popupBarTB->insertItem( "&Help", helpMenu );
+ if (QApplication::desktop()->width() > 320 ) {
+ // mViewManager->getFilterAction()->plug ( tb);
+ }
+#endif
+ // mActionQuit->plug ( mMainWindow->toolBar());
+
+
+
+ //US Now connect the actions with the menue entries.
+ mActionPrint->plug( fileMenu );
+ mActionMail->plug( fileMenu );
+ fileMenu->insertSeparator();
+
+ mActionNewContact->plug( fileMenu );
+ mActionNewContact->plug( tb );
+
+ mActionEditAddressee->plug( fileMenu );
+ fileMenu->insertSeparator();
+ mActionSave->plug( fileMenu );
+ fileMenu->insertItem( "&Import", ImportMenu );
+ fileMenu->insertItem( "&Emport", ExportMenu );
+ fileMenu->insertSeparator();
+ mActionMailVCard->plug( fileMenu );
+ fileMenu->insertSeparator();
+ mActionQuit->plug( fileMenu );
+
+
+ // edit menu
+ mActionUndo->plug( editMenu );
+ mActionRedo->plug( editMenu );
+ editMenu->insertSeparator();
+ mActionCut->plug( editMenu );
+ mActionCopy->plug( editMenu );
+ mActionPaste->plug( editMenu );
+ mActionDelete->plug( editMenu );
+ editMenu->insertSeparator();
+ mActionSelectAll->plug( editMenu );
+
+
+ // settings menu
+//US special menuentry to configure the addressbook resources. On KDE
+// you do that through the control center !!!
+ mActionConfigResources->plug( settingsMenu );
+ settingsMenu->insertSeparator();
+
+ mActionConfigKAddressbook->plug( settingsMenu );
+
+ if ( mIsPart ) {
+ mActionConfigShortcuts->plug( settingsMenu );
+ mActionConfigureToolbars->plug( settingsMenu );
+
+ } else {
+ mActionKeyBindings->plug( settingsMenu );
+ }
+
+ settingsMenu->insertSeparator();
+
+ mActionJumpBar->plug( settingsMenu );
+ mActionDetails->plug( settingsMenu );
+ settingsMenu->insertSeparator();
+
+ mActionWhoAmI->plug( settingsMenu );
+ mActionCategories->plug( settingsMenu );
+
+ mActionAboutKAddressbook->plug( helpMenu );
+
+ if (QApplication::desktop()->width() > 320 ) {
+
+ mActionEditAddressee->plug( tb );
+ mActionSave->plug( tb );
+ mViewManager->getFilterAction()->plug ( tb);
+ if (QApplication::desktop()->width() > 480 )
+ mActionDelete->plug( tb );
+ }
+ mActionQuit->plug ( tb );
+ // tb->insertWidget(-1, 0, mIncSearchWidget, 6);
+
+ //US link the searchwidget first to this.
+ // The real linkage to the toolbar happens later.
+//US mIncSearchWidget->reparent(tb, 0, QPoint(50,0), TRUE);
+//US tb->insertItem( mIncSearchWidget );
+/*US
+ mIncSearchWidget = new IncSearchWidget( tb );
+ connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ),
+ SLOT( incrementalSearch( const QString& ) ) );
+
+ mJumpButtonBar = new JumpButtonBar( this, this );
+
+//US topLayout->addWidget( mJumpButtonBar );
+ this->layout()->add( mJumpButtonBar );
+*/
+
+#endif //KAB_EMBEDDED
+}
+
+
+
+void KABCore::clipboardDataChanged()
+{
+
+ if ( mReadWrite )
+ mActionPaste->setEnabled( !QApplication::clipboard()->text().isEmpty() );
+
+}
+
+void KABCore::updateActionMenu()
+{
+ UndoStack *undo = UndoStack::instance();
+ RedoStack *redo = RedoStack::instance();
+
+ if ( undo->isEmpty() )
+ mActionUndo->setText( i18n( "Undo" ) );
+ else
+ mActionUndo->setText( i18n( "Undo %1" ).arg( undo->top()->name() ) );
+
+ mActionUndo->setEnabled( !undo->isEmpty() );
+
+ if ( !redo->top() )
+ mActionRedo->setText( i18n( "Redo" ) );
+ else
+ mActionRedo->setText( i18n( "Redo %1" ).arg( redo->top()->name() ) );
+
+ mActionRedo->setEnabled( !redo->isEmpty() );
+}
+
+void KABCore::configureKeyBindings()
+{
+#ifndef KAB_EMBEDDED
+ KKeyDialog::configure( actionCollection(), true );
+#else //KAB_EMBEDDED
+ qDebug("KABCore::configureKeyBindings() not implemented");
+#endif //KAB_EMBEDDED
+}
+
+#ifdef KAB_EMBEDDED
+void KABCore::configureResources()
+{
+ KRES::KCMKResources dlg( this, "" , 0 );
+
+ if ( !dlg.exec() )
+ return;
+}
+#endif //KAB_EMBEDDED
+
+
+
+#ifndef KAB_EMBEDDED
+#include "kabcore.moc"
+#endif //KAB_EMBEDDED
diff --git a/kaddressbook/kabcore.h b/kaddressbook/kabcore.h
new file mode 100644
index 0000000..edf98c2
--- a/dev/null
+++ b/kaddressbook/kabcore.h
@@ -0,0 +1,421 @@
+/*
+ This file is part of KAddressbook.
+ Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef KABCORE_H
+#define KABCORE_H
+
+#include <kabc/field.h>
+
+#ifndef KAB_EMBEDDED
+#endif //KAB_EMBEDDED
+#include <qdict.h>
+
+#include <qwidget.h>
+#include <qpopupmenu.h>
+
+namespace KABC {
+class AddressBook;
+}
+
+#ifndef KAB_EMBEDDED
+class KAboutData;
+class KConfig;
+
+class KAddressBookService;
+class LDAPSearchDialog;
+#else //KAB_EMBEDDED
+class KAddressBookMain;
+//US class QAction;
+#endif //KAB_EMBEDDED
+class KCMultiDialog;
+class KXMLGUIClient;
+class ExtensionManager;
+class XXPortManager;
+class JumpButtonBar;
+class IncSearchWidget;
+class KDGanttMinimizeSplitter;
+class KAction;
+class KActionCollection;
+class KToggleAction;
+
+class QAction;
+class QMenuBar;
+class QSplitter;
+class ViewContainer;
+class ViewManager;
+class AddresseeEditorDialog;
+
+class KABCore : public QWidget
+{
+ Q_OBJECT
+
+ public:
+ KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name = 0 );
+
+
+ ~KABCore();
+
+
+#ifdef KAB_EMBEDDED
+ //US added functionality
+ QPopupMenu* getViewMenu() {return viewMenu;}
+ QPopupMenu* getFilterMenu() {return filterMenu;}
+ QPopupMenu* getSettingsMenu() {return settingsMenu;}
+ void addActionsManually();
+#endif //KAB_EMBEDDED
+ /**
+ Restores the global settings.
+ */
+ void restoreSettings();
+
+ /**
+ Saves the global settings.
+ */
+ void saveSettings();
+
+ /**
+ Returns a pointer to the StdAddressBook of the application.
+ */
+ KABC::AddressBook *addressBook() const;
+
+ /**
+ Returns a pointer to the KConfig object of the application.
+ */
+ static KConfig *config();
+
+ /**
+ Returns a pointer to the global KActionCollection object. So
+ other classes can register their actions easily.
+ */
+ KActionCollection *actionCollection() const;
+
+ /**
+ Returns the current search field of the Incremental Search Widget.
+ */
+ KABC::Field *currentSearchField() const;
+
+ /**
+ Returns the uid list of the currently selected contacts.
+ */
+ QStringList selectedUIDs() const;
+
+ /**
+ Displays the ResourceSelectDialog and returns the selected
+ resource or a null pointer if no resource was selected by
+ the user.
+ */
+ KABC::Resource *requestResource( QWidget *parent );
+
+#ifndef KAB_EMBEDDED
+ static KAboutData *createAboutData();
+#endif //KAB_EMBEDDED
+
+#ifdef KAB_EMBEDDED
+ inline QPopupMenu* getImportMenu() { return ImportMenu;}
+ inline QPopupMenu* getExportMenu() { return ExportMenu;}
+#endif //KAB_EMBEDDED
+
+ public slots:
+#ifdef KAB_EMBEDDED
+ void createAboutData();
+#endif //KAB_EMBEDDED
+
+ void statusMessage(QString, int time = 0 );
+ /**
+ Is called whenever a contact is selected in the view.
+ */
+ void setContactSelected( const QString &uid );
+
+ /**
+ Opens the preferred mail composer with all selected contacts as
+ arguments.
+ */
+ void sendMail();
+
+ /**
+ Opens the preferred mail composer with the given contacts as
+ arguments.
+ */
+ void sendMail( const QString& email );
+
+
+ void mailVCard();
+ void mailVCard(const QStringList& uids);
+
+ /**
+ Starts the preferred web browser with the given URL as argument.
+ */
+ void browse( const QString& url );
+
+ /**
+ Select all contacts in the view.
+ */
+ void selectAllContacts();
+
+ /**
+ Deletes all selected contacts from the address book.
+ */
+ void deleteContacts();
+
+ /**
+ Deletes given contacts from the address book.
+
+ @param uids The uids of the contacts, which shall be deleted.
+ */
+ void deleteContacts( const QStringList &uids );
+
+ /**
+ Copys the selected contacts into clipboard for later pasting.
+ */
+ void copyContacts();
+
+ /**
+ Cuts the selected contacts and stores them for later pasting.
+ */
+ void cutContacts();
+
+ /**
+ Paste contacts from clipboard into the address book.
+ */
+ void pasteContacts();
+
+ /**
+ Paste given contacts into the address book.
+
+ @param list The list of addressee, which shall be pasted.
+ */
+ void pasteContacts( KABC::Addressee::List &list );
+
+ /**
+ Sets the whoAmI contact, that is used by many other programs to
+ get personal information about the current user.
+ */
+ void setWhoAmI();
+
+ /**
+ Displays the category dialog and applies the result to all
+ selected contacts.
+ */
+ void setCategories();
+
+ /**
+ Sets the field list of the Incremental Search Widget.
+ */
+ void setSearchFields( const KABC::Field::List &fields );
+
+ /**
+ Search with the current search field for a contact, that matches
+ the given text, and selects it in the view.
+ */
+ void incrementalSearch( const QString& text );
+
+ /**
+ Marks the address book as modified.
+ */
+ void setModified();
+ /**
+ Marks the address book as modified without refreshing the view.
+ */
+ void setModifiedWOrefresh();
+
+ /**
+ Marks the address book as modified concerning the argument.
+ */
+ void setModified( bool modified );
+
+ /**
+ Returns whether the address book is modified.
+ */
+ bool modified() const;
+
+ /**
+ Called whenever an contact is modified in the contact editor
+ dialog or the quick edit.
+ */
+ void contactModified( const KABC::Addressee &addr );
+
+ /**
+ DCOP METHODS.
+ */
+ void addEmail( QString addr );
+ void importVCard( const KURL& url, bool showPreview );
+ void importVCard( const QString& vCard, bool showPreview );
+ void newContact();
+ QString getNameByPhone( const QString& phone );
+ /**
+ END DCOP METHODS
+ */
+
+ /**
+ Saves the contents of the AddressBook back to disk.
+ */
+ void save();
+
+ /**
+ Undos the last command using the undo stack.
+ */
+ void undo();
+
+ /**
+ Redos the last command that was undone, using the redo stack.
+ */
+ void redo();
+
+ /**
+ Shows the edit dialog for the given uid. If the uid is QString::null,
+ the method will try to find a selected addressee in the view.
+ */
+ void editContact( const QString &uid /*US = QString::null*/ );
+//US added a second method without defaultparameter
+ void editContact2();
+
+ /**
+ Launches the configuration dialog.
+ */
+ void openConfigDialog();
+
+ /**
+ Launches the ldap search dialog.
+ */
+ void openLDAPDialog();
+
+ /**
+ Creates a KAddressBookPrinter, which will display the print
+ dialog and do the printing.
+ */
+ void print();
+
+ /**
+ Registers a new GUI client, so plugins can register its actions.
+ */
+ void addGUIClient( KXMLGUIClient *client );
+
+ signals:
+ void contactSelected( const QString &name );
+ void contactSelected( const QPixmap &pixmap );
+ public slots:
+ void setDetailsVisible( bool visible );
+ void setDetailsToState();
+ private slots:
+ void setJumpButtonBarVisible( bool visible );
+
+ void extensionModified( const KABC::Addressee::List &list );
+ void clipboardDataChanged();
+ void updateActionMenu();
+ void configureKeyBindings();
+#ifdef KAB_EMBEDDED
+ void configureResources();
+#endif //KAB_EMBEDDED
+
+ void slotEditorDestroyed( const QString &uid );
+ void configurationChanged();
+ void addressBookChanged();
+
+ private:
+ void initGUI();
+ void initActions();
+
+ AddresseeEditorDialog *createAddresseeEditorDialog( QWidget *parent,
+ const char *name = 0 );
+
+ KXMLGUIClient *mGUIClient;
+
+ KABC::AddressBook *mAddressBook;
+
+ ViewManager *mViewManager;
+ // QSplitter *mDetailsSplitter;
+ //QSplitter *mExtensionBarSplitter;
+ ViewContainer *mDetails;
+ KDGanttMinimizeSplitter* mMiniSplitter;
+ XXPortManager *mXXPortManager;
+ JumpButtonBar *mJumpButtonBar;
+ IncSearchWidget *mIncSearchWidget;
+ ExtensionManager *mExtensionManager;
+
+ KCMultiDialog *mConfigureDialog;
+
+#ifndef KAB_EMBEDDED
+
+ KCMultiDialog *mConfigureDialog;
+ LDAPSearchDialog *mLdapSearchDialog;
+#endif //KAB_EMBEDDED
+ QDict<AddresseeEditorDialog> mEditorDict;
+
+ bool mReadWrite;
+ bool mModified;
+ bool mIsPart;
+
+ //US file menu
+ KAction *mActionMail;
+ KAction* mActionPrint;
+ KAction* mActionNewContact;
+ KAction *mActionSave;
+ KAction *mActionEditAddressee;
+ KAction *mActionMailVCard;
+ KAction *mActionQuit;
+
+ //US edit menu
+ KAction *mActionCopy;
+ KAction *mActionCut;
+ KAction *mActionPaste;
+ KAction *mActionSelectAll;
+ KAction *mActionUndo;
+ KAction *mActionRedo;
+ KAction *mActionDelete;
+
+ //US settings menu
+ KAction *mActionConfigResources;
+ KAction *mActionConfigKAddressbook;
+ KAction *mActionConfigShortcuts;
+ KAction *mActionConfigureToolbars;
+ KAction *mActionKeyBindings;
+ KToggleAction *mActionJumpBar;
+ KToggleAction *mActionDetails;
+ KAction *mActionWhoAmI;
+ KAction *mActionCategories;
+ KAction *mActionAboutKAddressbook;
+
+ KAction *mActionDeleteView;
+
+ QPopupMenu *viewMenu;
+ QPopupMenu *filterMenu;
+ QPopupMenu *settingsMenu;
+
+//US QAction *mActionSave;
+ QPopupMenu *ImportMenu;
+ QPopupMenu *ExportMenu;
+
+#ifndef KAB_EMBEDDED
+ KAddressBookService *mAddressBookService;
+#endif //KAB_EMBEDDED
+
+ class KABCorePrivate;
+ KABCorePrivate *d;
+
+#ifdef KAB_EMBEDDED
+ KAddressBookMain *mMainWindow; // should be the same like mGUIClient
+#endif //KAB_EMBEDDED
+
+};
+
+#endif
diff --git a/kaddressbook/kabprefs.cpp b/kaddressbook/kabprefs.cpp
new file mode 100644
index 0000000..5b3b1ab
--- a/dev/null
+++ b/kaddressbook/kabprefs.cpp
@@ -0,0 +1,127 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+//US#ifdef KAB_EMBEDDED
+//#include <qstring.h>
+//#endif //KAB_EMBEDDED
+
+
+#include <kconfig.h>
+#include <klocale.h>
+#include <kstaticdeleter.h>
+//US#include <kdebug.h> // defines kdDebug()
+
+#include "kabprefs.h"
+
+KABPrefs *KABPrefs::sInstance = 0;
+static KStaticDeleter<KABPrefs> staticDeleter;
+
+KABPrefs::KABPrefs()
+ : KPimPrefs("kaddressbookrc")
+{
+ KPrefs::setCurrentGroup( "Views" );
+ addItemBool( "HonorSingleClick", &mHonorSingleClick, false );
+
+ KPrefs::setCurrentGroup( "General" );
+ addItemBool( "AutomaticNameParsing", &mAutomaticNameParsing, true );
+ addItemInt( "CurrentIncSearchField", &mCurrentIncSearchField, 0 );
+
+#ifdef KAB_EMBEDDED
+ addItemBool("AskForQuit",&mAskForQuit,false);
+ addItemBool("ToolBarHor",&mToolBarHor, true );
+ addItemBool("ToolBarUp",&mToolBarUp, false );
+#endif //KAB_EMBEDDED
+
+ KPrefs::setCurrentGroup( "MainWindow" );
+ addItemBool( "JumpButtonBarVisible", &mJumpButtonBarVisible, false );
+ addItemBool( "DetailsPageVisible", &mDetailsPageVisible, true );
+ addItemIntList( "ExtensionsSplitter", &mExtensionsSplitter );
+ addItemIntList( "DetailsSplitter", &mDetailsSplitter );
+
+ KPrefs::setCurrentGroup( "Extensions_General" );
+ QStringList defaultExtensions;
+ defaultExtensions << "merge";
+ defaultExtensions << "distribution_list_editor";
+ addItemInt( "CurrentExtension", &mCurrentExtension, 0 );
+ addItemStringList( "ActiveExtensions", &mActiveExtensions, defaultExtensions );
+
+ KPrefs::setCurrentGroup( "Views" );
+ QString defaultView = i18n( "Default Table View" );
+ addItemString( "CurrentView", &mCurrentView, defaultView );
+ addItemStringList( "ViewNames", &mViewNames, defaultView );
+
+ KPrefs::setCurrentGroup( "Filters" );
+ addItemInt( "CurrentFilter", &mCurrentFilter, 0 );
+
+}
+
+KABPrefs::~KABPrefs()
+{
+}
+
+KABPrefs *KABPrefs::instance()
+{
+ if ( !sInstance ) {
+#ifdef KAB_EMBEDDED
+ sInstance = staticDeleter.setObject( new KABPrefs() );
+#else //KAB_EMBEDDED
+ //US the following line has changed ???. Why
+ staticDeleter.setObject( sInstance, new KABPrefs() );
+#endif //KAB_EMBEDDED
+ sInstance->readConfig();
+ }
+
+ return sInstance;
+}
+
+void KABPrefs::setCategoryDefaults()
+{
+ mCustomCategories.clear();
+
+ mCustomCategories << i18n( "Business" ) << i18n( "Family" ) << i18n( "School" )
+ << i18n( "Customer" ) << i18n( "Friend" );
+}
+
+ // US introduce a nonconst way to return the config object.
+KConfig* KABPrefs::getConfig()
+{
+ return config();
+}
+
+
+/*US
+void KABPrefs::usrSetDefaults()
+{
+ KPimPrefs::usrSetDefaults();
+}
+
+void KABPrefs::usrReadConfig()
+{
+ KPimPrefs::usrReadConfig();
+}
+
+void KABPrefs::usrWriteConfig()
+{
+ KPimPrefs::usrWriteConfig();
+}
+*/
diff --git a/kaddressbook/kabprefs.h b/kaddressbook/kabprefs.h
new file mode 100644
index 0000000..370fc5b
--- a/dev/null
+++ b/kaddressbook/kabprefs.h
@@ -0,0 +1,88 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef KABPREFS_H
+#define KABPREFS_H
+
+#include <qstringlist.h>
+
+#include <libkdepim/kpimprefs.h>
+
+class KConfig;
+
+class KABPrefs : public KPimPrefs
+{
+ public:
+ virtual ~KABPrefs();
+
+ static KABPrefs *instance();
+
+ // General
+ bool mHonorSingleClick;
+ bool mAutomaticNameParsing;
+ int mCurrentIncSearchField;
+
+#ifdef KAB_EMBEDDED
+ // US introduce a nonconst way to return the config object.
+ KConfig* getConfig();
+
+ bool mToolBarHor;
+ bool mToolBarUp;
+ bool mAskForQuit;
+ /** Set preferences to default values */
+// void usrSetDefaults();
+
+ /** Read preferences from config file */
+// void usrReadConfig();
+
+ /** Write preferences to config file */
+// void usrWriteConfig();
+#endif //KAB_EMBEDDED
+
+
+ // GUI
+ bool mJumpButtonBarVisible;
+ bool mDetailsPageVisible;
+ QValueList<int> mExtensionsSplitter;
+ QValueList<int> mDetailsSplitter;
+
+ // Extensions stuff
+ int mCurrentExtension;
+ QStringList mActiveExtensions;
+
+ // Views stuff
+ QString mCurrentView;
+ QStringList mViewNames;
+
+ // Filter
+ int mCurrentFilter;
+
+ void setCategoryDefaults();
+
+ private:
+ KABPrefs();
+
+ static KABPrefs *sInstance;
+};
+
+#endif
diff --git a/kaddressbook/kaddressbook.desktop b/kaddressbook/kaddressbook.desktop
new file mode 100644
index 0000000..9cee2aa
--- a/dev/null
+++ b/kaddressbook/kaddressbook.desktop
@@ -0,0 +1,8 @@
+[Desktop Entry]
+Comment = KAddressbook
+Display = 640x480/144dpi,480x640/144dpi
+Exec = kapi
+Icon = kdepim/kaddressbook/kaddressbook
+Name = KA/Pi
+Type = Application
+CanFastload = 1
diff --git a/kaddressbook/kaddressbook.pro b/kaddressbook/kaddressbook.pro
new file mode 100644
index 0000000..761c3e7
--- a/dev/null
+++ b/kaddressbook/kaddressbook.pro
@@ -0,0 +1,166 @@
+TEMPLATE = app
+CONFIG = qt warn_on
+TARGET = kapi
+DESTDIR= ../bin
+
+include( ../variables.pri )
+
+
+INCLUDEPATH += . ./details ./features ./kcmconfigs ./xxport ../microkde ../microkde/kdecore ../microkde/kutils ../microkde/kio/kfile ../microkde/kdeui ../kabc ../ interfaces
+DEFINES += KAB_EMBEDDED KAB_NOSPLITTER DESKTOP_VERSION
+
+unix : {
+LIBS += ../bin/libmicrokdepim.so
+LIBS += ../bin/libmicrokde.so
+LIBS += ../bin/libmicrokabc.so
+LIBS += ../bin/libmicrokcal.so
+LIBS += -lldap
+OBJECTS_DIR = obj/unix
+MOC_DIR = moc/unix
+}
+win32: {
+DEFINES += _WIN32_
+LIBS += ../bin/microkdepim.lib
+LIBS += ../bin/microkcal.lib
+LIBS += ../bin/microkde.lib
+LIBS += ../bin/microkabc.lib
+QMAKE_LINK += /NODEFAULTLIB:LIBC
+OBJECTS_DIR = obj/win
+MOC_DIR = moc/win
+}
+
+
+
+
+
+
+
+
+INTERFACES = \
+# filteredit_base.ui \
+# kofilterview_base.ui \
+
+HEADERS = \
+features/mergewidget.h \
+features/distributionlistwidget.h \
+kcmconfigs/addresseewidget.h \
+kcmconfigs/extensionconfigdialog.h \
+kcmconfigs/kcmkabconfig.h \
+kcmconfigs/kabconfigwidget.h \
+addresseeeditordialog.h \
+addresseeeditorwidget.h \
+addresseditwidget.h \
+addresseeconfig.h \
+addresseeutil.h \
+emaileditwidget.h \
+filtereditdialog.h \
+kaddressbookmain.h \
+kabprefs.h \
+kabcore.h \
+viewmanager.h \
+extensionmanager.h \
+extensionwidget.h \
+kaddressbookview.h \
+geowidget.h \
+imagewidget.h \
+incsearchwidget.h \
+jumpbuttonbar.h \
+phoneeditwidget.h \
+secrecywidget.h \
+keywidget.h \
+nameeditdialog.h \
+filter.h \
+addviewdialog.h \
+configurewidget.h \
+viewconfigurewidget.h \
+viewconfigurefieldspage.h \
+viewconfigurefilterpage.h \
+typecombo.h \
+undo.h \
+undocmds.h \
+xxportmanager.h \
+xxportobject.h \
+xxportselectdialog.h \
+details/detailsviewcontainer.h \
+details/look_basic.h \
+details/look_html.h \
+views/kaddressbookiconview.h \
+views/kaddressbooktableview.h \
+views/kaddressbookcardview.h \
+views/configuretableviewdialog.h \
+views/configurecardviewdialog.h \
+views/cardview.h \
+views/colorlistbox.h \
+views/contactlistview.h \
+xxport/vcard_xxport.h \
+xxport/kde2_xxport.h \
+xxport/csv_xxport.h \
+xxport/csvimportdialog.h \
+#details/look_details.h \
+#mainwindoiw.h \
+# alarmclient.h \
+# calendarview.h \
+# customlistviewitem.h \
+# datenavigator.h
+
+SOURCES = \
+addresseeeditordialog.cpp \
+addresseeeditorwidget.cpp \
+addresseditwidget.cpp \
+addresseeconfig.cpp \
+addresseeutil.cpp \
+extensionmanager.cpp \
+features/mergewidget.cpp \
+features/distributionlistwidget.cpp \
+kcmconfigs/addresseewidget.cpp \
+kcmconfigs/extensionconfigdialog.cpp \
+kcmconfigs/kcmkabconfig.cpp \
+kcmconfigs/kabconfigwidget.cpp \
+emaileditwidget.cpp \
+filtereditdialog.cpp \
+mainembedded.cpp \
+kaddressbookmain.cpp \
+kabcore.cpp \
+kabprefs.cpp \
+viewmanager.cpp \
+kaddressbookview.cpp \
+extensionwidget.cpp \
+geowidget.cpp \
+imagewidget.cpp \
+incsearchwidget.cpp \
+jumpbuttonbar.cpp \
+phoneeditwidget.cpp \
+secrecywidget.cpp \
+keywidget.cpp \
+nameeditdialog.cpp \
+filter.cpp \
+addviewdialog.cpp \
+configurewidget.cpp \
+viewconfigurewidget.cpp \
+viewconfigurefieldspage.cpp \
+viewconfigurefilterpage.cpp \
+undo.cpp \
+undocmds.cpp \
+xxportmanager.cpp \
+xxportobject.cpp \
+xxportselectdialog.cpp \
+details/detailsviewcontainer.cpp \
+details/look_basic.cpp \
+details/look_html.cpp \
+views/kaddressbookiconview.cpp \
+views/kaddressbooktableview.cpp \
+views/kaddressbookcardview.cpp \
+views/configuretableviewdialog.cpp \
+views/configurecardviewdialog.cpp \
+views/cardview.cpp \
+views/contactlistview.cpp \
+views/colorlistbox.cpp \
+xxport/vcard_xxport.cpp \
+xxport/kde2_xxport.cpp \
+xxport/csv_xxport.cpp \
+xxport/csvimportdialog.cpp \
+#details/look_details.cpp \
+#mainwindow.cpp \
+# calendarview.cpp \
+# timespanview.cpp
+
diff --git a/kaddressbook/kaddressbookE.pro b/kaddressbook/kaddressbookE.pro
new file mode 100644
index 0000000..577dbf9
--- a/dev/null
+++ b/kaddressbook/kaddressbookE.pro
@@ -0,0 +1,154 @@
+TEMPLATE = app
+CONFIG += qt warn_on
+
+
+TARGET = kapi
+OBJECTS_DIR = obj/$(PLATFORM)
+MOC_DIR = moc/$(PLATFORM)
+DESTDIR=$(QPEDIR)/bin
+
+
+INCLUDEPATH += . ./details ./features ./kcmconfigs ./xxport ../microkde ../microkde/kdecore ../microkde/kutils ../microkde/kio/kfile ../microkde/kdeui ../kabc ../qtcompat ../ interfaces $(QPEDIR)/include
+DEFINES += KAB_EMBEDDED KAB_NOSPLITTER
+#DEFINES += KORG_NODND KORG_NOPLUGINS KORG_NOKABC KORG_NOARCHIVE KORG_NOMAIL
+#DEFINES += KORG_NOPRINTER KORG_NODCOP KORG_NOKALARMD KORG_NORESOURCEVIEW KORG_NOSPLITTER
+#DEFINES += KORG_NOLVALTERNATION
+LIBS += -lmicrokdepim
+#LIBS += -lmicrokcal
+LIBS += -lmicrokde
+LIBS += -lmicrokcal
+LIBS += -lmicroqtcompat
+LIBS += -lmicrokabc
+LIBS += -lqpe
+LIBS += -ljpeg
+LIBS += $(QTOPIALIB)
+LIBS += -L$(QPEDIR)/lib
+
+INTERFACES = \
+# filteredit_base.ui \
+# kofilterview_base.ui \
+
+HEADERS = \
+features/mergewidget.h \
+features/distributionlistwidget.h \
+kcmconfigs/addresseewidget.h \
+kcmconfigs/extensionconfigdialog.h \
+kcmconfigs/kcmkabconfig.h \
+kcmconfigs/kabconfigwidget.h \
+addresseeeditordialog.h \
+addresseeeditorwidget.h \
+addresseditwidget.h \
+addresseeconfig.h \
+addresseeutil.h \
+emaileditwidget.h \
+filtereditdialog.h \
+kaddressbookmain.h \
+kabprefs.h \
+kabcore.h \
+viewmanager.h \
+extensionmanager.h \
+extensionwidget.h \
+kaddressbookview.h \
+geowidget.h \
+imagewidget.h \
+incsearchwidget.h \
+jumpbuttonbar.h \
+phoneeditwidget.h \
+secrecywidget.h \
+keywidget.h \
+nameeditdialog.h \
+filter.h \
+addviewdialog.h \
+configurewidget.h \
+viewconfigurewidget.h \
+viewconfigurefieldspage.h \
+viewconfigurefilterpage.h \
+typecombo.h \
+undo.h \
+undocmds.h \
+xxportmanager.h \
+xxportobject.h \
+xxportselectdialog.h \
+details/detailsviewcontainer.h \
+details/look_basic.h \
+details/look_html.h \
+views/kaddressbookiconview.h \
+views/kaddressbooktableview.h \
+views/kaddressbookcardview.h \
+views/configuretableviewdialog.h \
+views/configurecardviewdialog.h \
+views/cardview.h \
+views/colorlistbox.h \
+views/contactlistview.h \
+xxport/vcard_xxport.h \
+xxport/kde2_xxport.h \
+xxport/csv_xxport.h \
+xxport/csvimportdialog.h \
+#details/look_details.h \
+#mainwindoiw.h \
+# alarmclient.h \
+# calendarview.h \
+# customlistviewitem.h \
+# datenavigator.h
+
+SOURCES = \
+addresseeeditordialog.cpp \
+addresseeeditorwidget.cpp \
+addresseditwidget.cpp \
+addresseeconfig.cpp \
+addresseeutil.cpp \
+extensionmanager.cpp \
+features/mergewidget.cpp \
+features/distributionlistwidget.cpp \
+kcmconfigs/addresseewidget.cpp \
+kcmconfigs/extensionconfigdialog.cpp \
+kcmconfigs/kcmkabconfig.cpp \
+kcmconfigs/kabconfigwidget.cpp \
+emaileditwidget.cpp \
+filtereditdialog.cpp \
+mainembedded.cpp \
+kaddressbookmain.cpp \
+kabcore.cpp \
+kabprefs.cpp \
+viewmanager.cpp \
+kaddressbookview.cpp \
+extensionwidget.cpp \
+geowidget.cpp \
+imagewidget.cpp \
+incsearchwidget.cpp \
+jumpbuttonbar.cpp \
+phoneeditwidget.cpp \
+secrecywidget.cpp \
+keywidget.cpp \
+nameeditdialog.cpp \
+filter.cpp \
+addviewdialog.cpp \
+configurewidget.cpp \
+viewconfigurewidget.cpp \
+viewconfigurefieldspage.cpp \
+viewconfigurefilterpage.cpp \
+undo.cpp \
+undocmds.cpp \
+xxportmanager.cpp \
+xxportobject.cpp \
+xxportselectdialog.cpp \
+details/detailsviewcontainer.cpp \
+details/look_basic.cpp \
+details/look_html.cpp \
+views/kaddressbookiconview.cpp \
+views/kaddressbooktableview.cpp \
+views/kaddressbookcardview.cpp \
+views/configuretableviewdialog.cpp \
+views/configurecardviewdialog.cpp \
+views/cardview.cpp \
+views/contactlistview.cpp \
+views/colorlistbox.cpp \
+xxport/vcard_xxport.cpp \
+xxport/kde2_xxport.cpp \
+xxport/csv_xxport.cpp \
+xxport/csvimportdialog.cpp \
+#details/look_details.cpp \
+#mainwindow.cpp \
+# calendarview.cpp \
+# timespanview.cpp
+
diff --git a/kaddressbook/kaddressbookmain.cpp b/kaddressbook/kaddressbookmain.cpp
new file mode 100644
index 0000000..92c32ca
--- a/dev/null
+++ b/kaddressbook/kaddressbookmain.cpp
@@ -0,0 +1,293 @@
+/*
+ This file is part of KAddressbook.
+ Copyright (c) 1999 Don Sanders <dsanders@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifdef KAB_EMBEDDED
+#include "kabprefs.h"
+#include <kglobal.h>
+#include <qmessagebox.h>
+#include <qtoolbar.h>
+#include <qapplication.h>
+#else //KAB_EMBEDDED
+#include <kedittoolbar.h>
+#include <kkeydialog.h>
+#include <kmessagebox.h>
+#include <kstatusbar.h>
+#endif //KAB_EMBEDDED
+#include <klocale.h>
+
+#include "kabcore.h"
+#include "kaddressbookmain.h"
+#include "kactioncollection.h"
+
+#ifdef KAB_EMBEDDED
+KAddressBookMain::KAddressBookMain() : KMainWindow( 0, "adrressbook" )
+#else //KAB_EMBEDDED
+//MOC_SKIP_BEGIN
+KAddressBookMain::KAddressBookMain() : DCOPObject( "KAddressBookIface" ), KMainWindow( 0 )
+//MOC_SKIP_END
+#endif //KAB_EMBEDDED
+{
+
+ setIcon(SmallIcon( "ka24" ) );
+#if 0
+ //US for embedded systems, create the toolbar before we initiate KABCore.
+ // KABCore will fill the toolbar with menues and icons
+ QMainWindow::ToolBarDock tbd;
+ tbd = Top;
+ iconToolBar = new QToolBar( this );
+ addToolBar (iconToolBar , tbd );
+ iconToolBar->setHorizontalStretchable(true);
+//US iconToolBar->setWidth(300);
+#endif // 0
+
+ mCore = new KABCore( this, true, this );
+
+#ifdef KAB_EMBEDDED
+ setCaption( i18n( "KAddressbook/Pi" ) );
+#else //KAB_EMBEDDED
+ setCaption( i18n( "Address Book Browser" ) );
+#endif //KAB_EMBEDDED
+
+ //mCore->restoreSettings();
+
+ initActions();
+
+ setCentralWidget( mCore );
+
+//US statusBar()->show();
+
+#ifndef KAB_EMBEDDED
+ setStandardToolBarMenuEnabled(true);
+
+ createGUI( "kaddressbookui.rc", false );
+
+
+#endif //KAB_EMBEDDED
+ setAutoSaveSettings();
+ qApp->processEvents();
+ mCore->restoreSettings();
+}
+
+KAddressBookMain::~KAddressBookMain()
+{
+ // mCore->saveSettings();
+}
+#ifndef DESKTOP_VERSION
+void KAddressBookMain::show ()
+{
+ static bool block = false;
+ if( block ) {
+ QWidget::show();
+ return;
+ } else {
+ block = true ;
+ QWidget::showFullScreen();
+ }
+ int min = 20;
+ if ( QApplication::desktop()->width() > 320 )
+ min += 20;
+ setGeometry( 0,0,QApplication::desktop()->width(), QApplication::desktop()->height() - min );
+ block = false;
+}
+#endif
+void KAddressBookMain::showMinimized ()
+{
+ QWidget::showMinimized () ;
+}
+void KAddressBookMain::addEmail( QString addr )
+{
+ mCore->addEmail( addr );
+}
+
+#ifndef KAB_EMBEDDED
+ASYNC KAddressBookMain::showContactEditor( QString uid )
+{
+ mCore->editContact( uid );
+}
+#endif //KAB_EMBEDDED
+void KAddressBookMain::newContact()
+{
+ mCore->newContact();
+}
+
+QString KAddressBookMain::getNameByPhone( QString phone )
+{
+ return mCore->getNameByPhone( phone );
+}
+
+void KAddressBookMain::save()
+{
+ mCore->save();
+}
+
+void KAddressBookMain::exit()
+{
+ close( );
+}
+
+void KAddressBookMain::saveProperties( KConfig* )
+{
+}
+
+void KAddressBookMain::readProperties( KConfig* )
+{
+}
+
+void KAddressBookMain::initActions()
+{
+#ifndef KAB_EMBEDDED
+ KStdAction::quit( this, SLOT( close() ), actionCollection() );
+ KStdAction::configureToolbars( this, SLOT( configureToolbars() ), actionCollection() );
+#else //KAB_EMBEDDED
+ //US: transfered the setup of the actions into KABCore
+#endif //KAB_EMBEDDED
+
+
+}
+
+//US new method to setup menues and toolbars on embedded systems
+#ifdef KAB_EMBEDDED
+/*
+QToolBar * KAddressBookMain::getIconToolBar()
+{
+ return iconToolBar;
+}
+*/
+
+void KAddressBookMain::createGUI()
+{
+
+
+
+}
+#endif //KAB_EMBEDDED
+
+void KAddressBookMain::configureToolbars()
+{
+#ifndef KAB_EMBEDDED
+ saveMainWindowSettings( KGlobal::config(), "MainWindow" );
+
+ KEditToolbar dlg( factory() );
+ connect( &dlg, SIGNAL( newToolbarConfig() ), SLOT( slotNewToolbarConfig() ) );
+
+ dlg.exec();
+#else //KAB_EMBEDDED
+ qDebug("KAddressBookMain::configureToolbars() not implemented by ulf" );
+#endif //KAB_EMBEDDED
+}
+
+void KAddressBookMain::slotNewToolbarConfig()
+{
+#ifndef KAB_EMBEDDED
+ applyMainWindowSettings( KGlobal::config(), "MainWindow" );
+#else //KAB_EMBEDDED
+ qDebug("KAddressBookMain::slotNewToolbarConfig() not implemented by ulf" );
+#endif //KAB_EMBEDDED
+}
+
+void KAddressBookMain::configureKeys()
+{
+#ifndef KAB_EMBEDDED
+ KKeyDialog::configureKeys( actionCollection(), xmlFile(), true, this );
+#else //KAB_EMBEDDED
+ qDebug("KAddressBookMain::configureKeys() not implemented by ulf" );
+#endif //KAB_EMBEDDED
+}
+
+void KAddressBookMain::closeEvent( QCloseEvent* ce )
+{
+ QString mess = i18n( "Close KA/Pi?");
+ if ( mCore->modified() )
+ mess += i18n( "\n\nChanges will be saved!");
+ else
+ mess += i18n( "\n\nNo unsaved changes detected!\nNothing will be saved!");
+
+ switch( QMessageBox::information( this, "KA/Pi", mess ,
+ i18n("Yes!"), i18n("No"), 0, 0 ) ) {
+ case 0:
+
+ break;
+ case 1:
+ return;
+ break;
+ case 2:
+ return;
+ break;
+
+ default:
+ return;
+ break;
+ }
+
+#if 0
+
+ if ( mCore->modified() ) {
+ QString text = i18n( "The address book has been modified.\nDo you want to save your changes?" );
+
+#ifndef KAB_EMBEDDED
+ int ret = KMessageBox::warningYesNoCancel( this, text, "",
+ KStdGuiItem::yes(),
+ KStdGuiItem::no(), "AskForSave" );
+ switch ( ret ) {
+ case KMessageBox::Yes:
+ save();
+ break;
+ case KMessageBox::No:
+ return true;
+ break;
+ default: //cancel
+ return ;
+ break;
+ }
+
+#else //KAB_EMBEDDED
+ switch( QMessageBox::information( this, "KA/Pi",
+ text,
+ i18n("Yes!"), i18n("No"), 0, 0 ) ) {
+ case 0:
+ save();
+ break;
+ case 1:
+ break;
+ case 2:
+ return;
+ default:
+ return;
+ break;
+ }
+#endif //KAB_EMBEDDED
+ }
+
+#endif
+
+ save();
+ mCore->saveSettings();
+ KABPrefs::instance()->writeConfig();
+ ce->accept();
+
+}
+
+#ifndef KAB_EMBEDDED
+#include "kaddressbookmain.moc"
+#endif //KAB_EMBEDDED
+
diff --git a/kaddressbook/kaddressbookmain.h b/kaddressbook/kaddressbookmain.h
new file mode 100644
index 0000000..81ae09c
--- a/dev/null
+++ b/kaddressbook/kaddressbookmain.h
@@ -0,0 +1,126 @@
+/*
+ This file is part of KAddressbook.
+ Copyright (c) 1999 Don Sanders <dsanders@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef KADDRESSBOOKMAIN_H
+#define KADDRESSBOOKMAIN_H
+
+#include <qptrlist.h>
+
+#ifdef KAB_EMBEDDED
+class QToolBar;
+#include <qaction.h>
+//#include <qmainwindow.h>
+#include <kmainwindow.h>
+#else //KAB_EMBEDDED
+#include <kaction.h>
+#include <kapplication.h>
+#include <kmainwindow.h>
+#include "kaddressbookiface.h"
+#endif //KAB_EMBEDDED
+
+class KABCore;
+class KConfig;
+
+/**
+ This class serves as the main window for KAddressBook. It handles the
+ menus, toolbars, and status bars.
+
+ @short Main window class
+ @author Don Sanders <dsanders@kde.org>
+ @version 0.1
+ */
+#ifdef KAB_EMBEDDED
+class KAddressBookMain : public KMainWindow
+#else //KAB_EMBEDDED
+//MOC_SKIP_BEGIN
+class KAddressBookMain : public KMainWindow, virtual public KAddressBookIface
+//MOC_SKIP_END
+#endif //KAB_EMBEDDED
+{
+ Q_OBJECT
+
+ public:
+ KAddressBookMain();
+ virtual ~KAddressBookMain();
+
+#ifdef KAB_EMBEDDED
+// QPEToolBar * getIconToolBar();
+ // QToolBar * getIconToolBar();
+#endif //KAB_EMBEDDED
+
+
+ public slots:
+#ifndef DESKTOP_VERSION
+ void show();
+#endif
+
+ void showMinimized () ;
+ virtual void addEmail( QString addr );
+#ifndef KAB_EMBEDDED
+//MOC_SKIP_BEGIN
+ virtual ASYNC showContactEditor( QString uid );
+//MOC_SKIP_END
+#endif //KAB_EMBEDDED
+ virtual void newContact();
+ virtual QString getNameByPhone( QString phone );
+ virtual void save();
+ virtual void exit();
+
+ protected:
+ void initActions();
+#ifdef KAB_EMBEDDED
+ //US new method to setup menues and toolbars on embedded systems
+ void createGUI();
+#endif //KAB_EMBEDDED
+
+ /**
+ This function is called when it is time for the app to save its
+ properties for session management purposes.
+ */
+ void saveProperties( KConfig* );
+
+ /**
+ This function is called when this app is restored. The KConfig
+ object points to the session management config file that was saved
+ with @ref saveProperties
+ */
+ void readProperties( KConfig* );
+
+ void closeEvent( QCloseEvent* ce );
+
+ protected slots:
+ void configureToolbars();
+ void configureKeys();
+
+ void slotNewToolbarConfig();
+
+ private:
+ KABCore *mCore;
+
+#ifdef KAB_EMBEDDED
+ // QToolBar *iconToolBar;
+#endif //KAB_EMBEDDED
+
+};
+
+#endif
diff --git a/kaddressbook/kaddressbookview.cpp b/kaddressbook/kaddressbookview.cpp
new file mode 100644
index 0000000..a44fd82
--- a/dev/null
+++ b/kaddressbook/kaddressbookview.cpp
@@ -0,0 +1,171 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef KAB_EMBEDDED
+#include <qapplication.h>
+
+#include <kabc/distributionlistdialog.h>
+#include <kconfig.h>
+#include <klocale.h>
+
+#include "viewmanager.h"
+
+#endif //KAB_EMBEDDED
+#include <qlayout.h>
+
+#include <kabc/addressbook.h>
+#include <kdebug.h>
+
+#include "kaddressbookview.h"
+
+KAddressBookView::KAddressBookView( KABC::AddressBook *ab, QWidget *parent,
+ const char *name )
+ : QWidget( parent, name ), mAddressBook( ab ), mFieldList()
+{
+ initGUI();
+}
+
+KAddressBookView::~KAddressBookView()
+{
+ kdDebug(5720) << "KAddressBookView::~KAddressBookView: destroying - "
+ << name() << endl;
+}
+
+void KAddressBookView::readConfig( KConfig *config )
+{
+ mFieldList = KABC::Field::restoreFields( config, "KABCFields" );
+
+ if ( mFieldList.isEmpty() )
+ mFieldList = KABC::Field::defaultFields();
+
+ mDefaultFilterType = (DefaultFilterType)config->readNumEntry( "DefaultFilterType", 1 );
+ mDefaultFilterName = config->readEntry( "DefaultFilterName", QString::null );
+}
+
+void KAddressBookView::writeConfig( KConfig* )
+{
+ // Most of writing the config is handled by the ConfigureViewDialog
+}
+
+QString KAddressBookView::selectedEmails()
+{
+#ifndef KAB_EMBEDDED
+
+ bool first = true;
+ QString emailAddrs;
+ QStringList uidList = selectedUids();
+ KABC::Addressee addr;
+ QString email;
+
+ QStringList::Iterator it;
+ for ( it = uidList.begin(); it != uidList.end(); ++it ) {
+ addr = mAddressBook->findByUid( *it );
+
+ if ( !addr.isEmpty() ) {
+ QString m = QString::null;
+
+ if ( addr.emails().count() > 1 )
+ m = KABC::EmailSelector::getEmail( addr.emails(), addr.preferredEmail(), this );
+
+ email = addr.fullEmail( m );
+
+ if ( !first )
+ emailAddrs += ", ";
+ else
+ first = false;
+
+ emailAddrs += email;
+ }
+ }
+
+ return emailAddrs;
+#else //KAB_EMBEDDED
+qDebug("KAddressBookView::selectedEmails() update method");
+return 0;
+#endif //KAB_EMBEDDED
+
+}
+
+KABC::Addressee::List KAddressBookView::addressees()
+{
+ KABC::Addressee::List addresseeList;
+
+ KABC::AddressBook::Iterator it;
+ for (it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) {
+ if ( mFilter.filterAddressee( *it ) )
+ addresseeList.append( *it );
+ }
+
+ return addresseeList;
+}
+
+void KAddressBookView::initGUI()
+{
+ // Create the layout
+ QVBoxLayout *layout = new QVBoxLayout( this );
+
+ // Add the view widget
+ mViewWidget = new QWidget( this );
+ layout->addWidget( mViewWidget );
+}
+
+KABC::Field::List KAddressBookView::fields() const
+{
+ return mFieldList;
+}
+
+void KAddressBookView::setFilter( const Filter &filter )
+{
+ mFilter = filter;
+}
+
+KAddressBookView::DefaultFilterType KAddressBookView::defaultFilterType() const
+{
+ return mDefaultFilterType;
+}
+
+const QString &KAddressBookView::defaultFilterName() const
+{
+ return mDefaultFilterName;
+}
+
+KABC::AddressBook *KAddressBookView::addressBook() const
+{
+ return mAddressBook;
+}
+
+QWidget *KAddressBookView::viewWidget()
+{
+ return mViewWidget;
+}
+
+ViewConfigureWidget *ViewFactory::configureWidget( KABC::AddressBook *ab,
+ QWidget *parent,
+ const char *name )
+{
+ return new ViewConfigureWidget( ab, parent, name );
+}
+
+#ifndef KAB_EMBEDDED
+#include "kaddressbookview.moc"
+#endif //KAB_EMBEDDED
diff --git a/kaddressbook/kaddressbookview.h b/kaddressbook/kaddressbookview.h
new file mode 100644
index 0000000..7457080
--- a/dev/null
+++ b/kaddressbook/kaddressbookview.h
@@ -0,0 +1,295 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef KADDRESSBOOKVIEW_H
+#define KADDRESSBOOKVIEW_H
+
+#ifndef KAB_EMBEDDED
+#include <klibloader.h>
+#endif //KAB_EMBEDDED
+
+class KConfig;
+class QDropEvent;
+
+#include <qstringlist.h>
+#include <kabc/field.h>
+#include <qwidget.h>
+
+#include "viewconfigurewidget.h"
+#include "filter.h"
+
+namespace KABC { class AddressBook; }
+
+/**
+ Base class for all views in kaddressbook. This class implements
+ all the common methods needed to provide a view to the user.
+
+ To implement a specific view (table, card, etc), just inherit from
+ this class and implement all the pure virtuals.
+
+ @author Mike Pilone <mpilone@slac.com>
+ */
+class KAddressBookView : public QWidget
+{
+ Q_OBJECT
+
+ public:
+ enum DefaultFilterType { None = 0, Active = 1, Specific = 2 };
+
+ KAddressBookView( KABC::AddressBook *ab, QWidget *parent, const char *name );
+ virtual ~KAddressBookView();
+
+ /**
+ Must be overloaded in subclasses. Should return a list of
+ all the uids of selected contacts.
+ */
+ virtual QStringList selectedUids() = 0;
+
+ /**
+ Called whenever this view should read the config. This can be used
+ as a sign that the config has changed, therefore the view should
+ assume the worst and rebuild itself if necessary. For example,
+ in a table view this method may be called when the user adds or
+ removes columns from the view.
+
+ If overloaded in the subclass, do not forget to call super class's
+ method.
+
+ @param config The KConfig object to read from. The group will already
+ be set, so do not change the group.
+ */
+ virtual void readConfig( KConfig *config );
+
+ /**
+ Called whenever this view should write the config. The view should not
+ write out information handled by the application, such as which fields
+ are visible. The view should only write out information specific
+ to itself (i.e.: All information in the ViewConfigWidget)
+
+ If overloaded in the subclass, do not forget to call the super class's
+ method.
+
+ @param config The KConfig object to read from. The group will already
+ be set, so do not change the group.
+ */
+ virtual void writeConfig( KConfig *config );
+
+ /**
+ Returns a QString with all the selected email addresses concatenated
+ together with a ',' seperator.
+ */
+ virtual QString selectedEmails();
+
+ /**
+ Return the type of the view: Icon, Table, etc. Please make sure that
+ this is the same value that ViewWrapper::type() will return for your
+ view.
+ */
+ virtual QString type() const = 0;
+
+ /**
+ Returns a list of the fields that should be displayed. The list
+ is composed of the fields proper names (ie: Home Address), so
+ the view may need to translate them in order to get the
+ value from the addressee.
+
+ This list is generated from the config file, so it is advisable to call
+ this method whenever a readConfig() is called in order to get the newest
+ list of fields.
+ */
+ KABC::Field::List fields() const;
+
+ /**
+ Sets the active filter. This filter will be used for filtering
+ the list of addressees to display. The view will <b>not</b>
+ automatically refresh itself, so in most cases you will want to call
+ KAddressBookView::refresh() after this method.
+ */
+ void setFilter( const Filter& );
+
+ /**
+ @return The default filter type selection. If the selection
+ is SpecificFilter, the name of the filter can be retrieved with
+ defaultFilterName()
+ */
+ DefaultFilterType defaultFilterType() const;
+
+ /**
+ @return The name of the default filter. This string is
+ only valid if defaultFilterType() is returning SpecificFilter.
+ */
+ const QString &defaultFilterName() const;
+
+ /**
+ @return The address book.
+ */
+ KABC::AddressBook *addressBook() const;
+
+ public slots:
+ /**
+ Must be overloaded in subclasses to refresh the view.
+ Refreshing includes updating the view to ensure that only items
+ in the document are visible. If <i>uid</i> is valid, only the
+ addressee with uid needs to be refreshed. This is an optimization
+ only.
+ */
+ virtual void refresh( QString uid = QString::null ) = 0;
+
+ /**
+ This method must be overloaded in subclasses. Select (highlight)
+ the addressee matching <i>uid</i>. If uid
+ is equal to QString::null, then all addressees should be selected.
+ */
+#ifndef KAB_EMBEDDED
+//MOC_SKIP_BEGIN
+ virtual void setSelected( QString uid = QString::null, bool selected = true ) = 0;
+//MOC_SKIP_END
+#else //KAB_EMBEDDED
+ //US my moc can not handle the default parameters. Is this a problem ???
+ virtual void setSelected( QString uid, bool selected) = 0;
+#endif //KAB_EMBEDDED
+
+ signals:
+ /**
+ This signal should be emitted by a subclass whenever an addressee
+ is modified.
+ */
+ void modified();
+
+ /**
+ This signal should be emitted by a subclass whenever an addressee
+ is selected. Selected means that the addressee was given the focus.
+ Some widgets may call this 'highlighted'. The view is responsible for
+ emitting this signal multiple times if multiple items are selected,
+ with the last item selected being the last emit.
+
+ @param uid The uid of the selected addressee.
+
+ @see KListView
+ */
+ void selected( const QString &uid );
+ void deleteRequest();
+ /**
+ This signal should be emitted by a subclass whenever an addressee
+ is executed. This is defined by the KDE system wide config, but it
+ either means single or doubleclicked.
+
+ @param ui The uid of the selected addressee
+
+ @see KListView
+ */
+ void executed( const QString &uid );
+
+ /**
+ This signal is emitted whenever a user attempts to start a drag
+ in the view. The slot connected to this signal would usually want
+ to create a QDragObject.
+ */
+ void startDrag();
+
+ /**
+ This signal is emitted whenever the user drops something on the
+ view. The individual view should handle checking if the item is
+ droppable (ie: if it is a vcard).
+ */
+ void dropped( QDropEvent* );
+
+ protected:
+ /**
+ Returns a list of the addressees that should be displayed. This method
+ should always be used by the subclass to get a list of addressees. This
+ method internally takes many factors into account, including the current
+ filter.
+ */
+ KABC::Addressee::List addressees();
+
+ /**
+ This method returns the widget that should be used as the parent for
+ all view components. By using this widget as the parent and not
+ 'this', the view subclass has the option of placing other widgets
+ around the view (ie: search fields, etc). Do not delete this widget!
+ */
+ QWidget *viewWidget();
+
+ private:
+ void initGUI();
+
+ DefaultFilterType mDefaultFilterType;
+ Filter mFilter;
+ QString mDefaultFilterName;
+ KABC::AddressBook *mAddressBook;
+ KABC::Field::List mFieldList;
+
+ QWidget *mViewWidget;
+};
+
+#ifndef KAB_EMBEDDED
+//MOC_SKIP_BEGIN
+class ViewFactory : public KLibFactory
+//MOC_SKIP_END
+#else //KAB_EMBEDDED
+class ViewFactory
+#endif //KAB_EMBEDDED
+{
+
+ public:
+ virtual KAddressBookView *view( KABC::AddressBook *ab, QWidget *parent,
+ const char *name = 0 ) = 0;
+
+ /**
+ @return The type of the view. This is normally a small one word
+ string (ie: Table, Icon, Tree, etc).
+ */
+ virtual QString type() const = 0;
+
+ /**
+ @return The description of the view. This should be a 3 to
+ 4 line string (don't actually use return characters in the string)
+ describing the features offered by the view.
+ */
+ virtual QString description() const = 0;
+
+ /**
+ Creates a config dialog for the view type. The default
+ implementation will return a ViewConfigDialog. This default
+ dialog will allow the user to set the visible fields only. If
+ you need more config options (as most views will), this method
+ can be overloaded to return your sublcass of ViewConfigDialog.
+ If this method is over loaded the base classes method should
+ <B>not</B> be called.
+ */
+ virtual ViewConfigureWidget *configureWidget( KABC::AddressBook *ab,
+ QWidget *parent,
+ const char *name = 0 );
+
+ protected:
+ virtual QObject* createObject( QObject*, const char*, const char*,
+ const QStringList & )
+ {
+ return 0;
+ }
+
+};
+
+
+#endif
diff --git a/kaddressbook/kcmconfigs/addresseewidget.cpp b/kaddressbook/kcmconfigs/addresseewidget.cpp
new file mode 100644
index 0000000..0f3c353
--- a/dev/null
+++ b/kaddressbook/kcmconfigs/addresseewidget.cpp
@@ -0,0 +1,236 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include <qgroupbox.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qlistbox.h>
+#include <qpushbutton.h>
+
+#include <kbuttonbox.h>
+#include <kcombobox.h>
+#include <kconfig.h>
+#include <kdialog.h>
+#include <klocale.h>
+#include <kglobal.h>
+#include <klineedit.h>
+#include <kstandarddirs.h>
+
+#include "addresseewidget.h"
+
+NamePartWidget::NamePartWidget( const QString &title, QWidget *parent,
+ const char *name )
+ : QWidget( parent, name )
+{
+ if (KGlobal::getOrientation() == KGlobal::Portrait)
+ {
+ QGridLayout* layout = new QGridLayout( this, 1, 1, KDialog::marginHintSmall(),
+ KDialog::spacingHintSmall() );
+
+ QLabel *label = new QLabel( i18n( title ), this );
+ layout->addWidget( label, 0, 1 );
+
+ mBox = new QListBox( this );
+ mBox->setMaximumSize(70, 70);
+ layout->addMultiCellWidget( mBox, 0, 1, 0, 0 );
+
+ KButtonBox *bbox = new KButtonBox( this, Qt::Vertical );
+ mAddButton = bbox->addButton( i18n( "Add" ), this, SLOT( add() ) );
+ mRemoveButton = bbox->addButton( i18n( "Rem" ), this, SLOT( remove() ) );
+ bbox->layout();
+ layout->addMultiCellWidget( bbox, 0, 2, 2,2);
+
+ mEdit = new KLineEdit( this );
+ layout->addWidget( mEdit, 1, 1 );
+ //mEdit->setMinimumWidth(50);
+
+// layout->addWidget( group );
+
+ }
+ else
+ {
+ QHBoxLayout *layout = new QHBoxLayout( this );
+
+ QGroupBox *group = new QGroupBox( 0, Qt::Vertical, title, this );
+ QGridLayout *groupLayout = new QGridLayout( group->layout(), 2, 2,
+ KDialog::spacingHint() );
+
+ mBox = new QListBox( group );
+
+ groupLayout->addWidget( mBox, 0, 0 );
+
+ KButtonBox *bbox = new KButtonBox( group, Qt::Vertical );
+ mAddButton = bbox->addButton( i18n( "Add" ), this, SLOT( add() ) );
+ mRemoveButton = bbox->addButton( i18n( "Remove" ), this, SLOT( remove() ) );
+ bbox->layout();
+ groupLayout->addWidget( bbox, 0, 1 );
+
+ mEdit = new KLineEdit( group );
+ groupLayout->addMultiCellWidget( mEdit, 1, 1, 0, 1 );
+
+ layout->addWidget( group );
+
+ }
+
+ mAddButton->setEnabled( false );
+ mRemoveButton->setEnabled( false );
+
+
+ connect( mBox, SIGNAL( selectionChanged( QListBoxItem* ) ),
+ SLOT( selectionChanged( QListBoxItem* ) ) );
+ connect( mEdit, SIGNAL( textChanged( const QString& ) ),
+ SLOT( textChanged( const QString& ) ) );
+ connect( mEdit, SIGNAL( returnPressed() ), SLOT( add() ) );
+
+}
+
+NamePartWidget::~NamePartWidget()
+{
+}
+
+void NamePartWidget::setNameParts( const QStringList &list )
+{
+ mBox->clear();
+ mBox->insertStringList( list );
+}
+
+QStringList NamePartWidget::nameParts() const
+{
+ QStringList parts;
+ for ( uint i = 0; i < mBox->count(); ++i )
+ parts.append( mBox->text( i ) );
+
+ return parts;
+}
+
+void NamePartWidget::add()
+{
+ if ( !mEdit->text().isEmpty() ) {
+ mBox->insertItem( mEdit->text() );
+ emit modified();
+ }
+
+ mEdit->setText( "" );
+}
+
+void NamePartWidget::remove()
+{
+ mBox->removeItem( mBox->currentItem() );
+ if ( mBox->count() == 0 )
+ selectionChanged( 0 );
+
+ emit modified();
+}
+
+void NamePartWidget::selectionChanged( QListBoxItem *item )
+{
+ mRemoveButton->setEnabled( item != 0 );
+}
+
+void NamePartWidget::textChanged( const QString& text )
+{
+ mAddButton->setEnabled( !text.isEmpty() );
+}
+
+
+AddresseeWidget::AddresseeWidget( QWidget *parent, const char *name )
+ : QWidget( parent, name )
+{
+ QGridLayout *layout;
+
+ mPrefix = new NamePartWidget( i18n( "Prefixes" ), this );
+ mInclusion = new NamePartWidget( i18n( "Inclusions" ), this );
+ mSuffix = new NamePartWidget( i18n( "Suffixes" ), this );
+ QLabel *label = new QLabel( i18n( "Default formatted name:" ), this );
+
+ mFormattedNameCombo = new KComboBox( this );
+ mFormattedNameCombo->insertItem( i18n( "Empty" ) );
+ mFormattedNameCombo->insertItem( i18n( "Simple Name" ) );
+ mFormattedNameCombo->insertItem( i18n( "Full Name" ) );
+ mFormattedNameCombo->insertItem( i18n( "Reverse Name" ) );
+
+ if (KGlobal::getOrientation() == KGlobal::Portrait)
+ {
+ layout = new QGridLayout( this, 4, 2, KDialog::marginHint(),
+ KDialog::spacingHint() );
+
+ layout->addMultiCellWidget( mPrefix, 0, 0, 0, 1 );
+ layout->addMultiCellWidget( mInclusion, 1, 1, 0, 1 );
+ layout->addMultiCellWidget( mSuffix, 2, 2, 0, 1 );
+ layout->addWidget( label, 3, 0 );
+ layout->addWidget( mFormattedNameCombo, 3, 1 );
+
+ }
+ else
+ {
+ layout = new QGridLayout( this, 2, 3, KDialog::marginHint(),
+ KDialog::spacingHint() );
+
+ layout->addWidget( mPrefix, 0, 0 );
+ layout->addWidget( mInclusion, 0, 1 );
+ layout->addWidget( mSuffix, 0, 2 );
+ layout->addWidget( label, 1, 0 );
+ layout->addMultiCellWidget( mFormattedNameCombo, 1, 1, 1, 2 );
+ }
+
+ connect( mPrefix, SIGNAL( modified() ), SIGNAL( modified() ) );
+ connect( mInclusion, SIGNAL( modified() ), SIGNAL( modified() ) );
+ connect( mSuffix, SIGNAL( modified() ), SIGNAL( modified() ) );
+ connect( mFormattedNameCombo, SIGNAL( activated( int ) ), SIGNAL( modified() ) );
+}
+
+AddresseeWidget::~AddresseeWidget()
+{
+}
+
+void AddresseeWidget::restoreSettings()
+{
+ KConfig config( locateLocal("config", "kabcrc") );
+ config.setGroup( "General" );
+
+ mPrefix->setNameParts( config.readListEntry( "Prefixes" ) );
+ mInclusion->setNameParts( config.readListEntry( "Inclusions" ) );
+ mSuffix->setNameParts( config.readListEntry( "Suffixes" ) );
+
+ KConfig cfg( locateLocal("config","kaddressbookrc") );
+ cfg.setGroup( "General" );
+ mFormattedNameCombo->setCurrentItem( cfg.readNumEntry( "FormattedNameType", 1 ) );
+}
+
+void AddresseeWidget::saveSettings()
+{
+ KConfig config( locateLocal("config","kabcrc") );
+ config.setGroup( "General" );
+
+ config.writeEntry( "Prefixes", mPrefix->nameParts() );
+ config.writeEntry( "Inclusions", mInclusion->nameParts() );
+ config.writeEntry( "Suffixes", mSuffix->nameParts() );
+
+ KConfig cfg( locateLocal("config","kaddressbookrc") );
+ cfg.setGroup( "General" );
+ cfg.writeEntry( "FormattedNameType", mFormattedNameCombo->currentItem() );
+}
+
+#ifndef KAB_EMBEDDED
+#include "addresseewidget.moc"
+#endif //KAB_EMBEDDED
diff --git a/kaddressbook/kcmconfigs/addresseewidget.h b/kaddressbook/kcmconfigs/addresseewidget.h
new file mode 100644
index 0000000..09330c8
--- a/dev/null
+++ b/kaddressbook/kcmconfigs/addresseewidget.h
@@ -0,0 +1,87 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef ADDRESSEEWIDGET_H
+#define ADDRESSEEWIDGET_H
+
+#include <qwidget.h>
+
+class KComboBox;
+class KLineEdit;
+
+class QListBox;
+class QListBoxItem;
+class QPushButton;
+
+class NamePartWidget : public QWidget
+{
+ Q_OBJECT
+
+ public:
+ NamePartWidget( const QString &title, QWidget *parent,
+ const char *name = 0 );
+ ~NamePartWidget();
+
+ void setNameParts( const QStringList &list );
+ QStringList nameParts() const;
+
+ signals:
+ void modified();
+
+ private slots:
+ void add();
+ void remove();
+
+ void selectionChanged( QListBoxItem* );
+ void textChanged( const QString& );
+
+ private:
+ KLineEdit *mEdit;
+
+ QListBox *mBox;
+ QPushButton *mAddButton;
+ QPushButton *mRemoveButton;
+};
+
+class AddresseeWidget : public QWidget
+{
+ Q_OBJECT
+
+ public:
+ AddresseeWidget( QWidget *parent, const char *name = 0 );
+ ~AddresseeWidget();
+
+ void restoreSettings();
+ void saveSettings();
+
+ signals:
+ void modified();
+
+ private:
+ KComboBox *mFormattedNameCombo;
+ NamePartWidget *mPrefix;
+ NamePartWidget *mInclusion;
+ NamePartWidget *mSuffix;
+};
+
+#endif
diff --git a/kaddressbook/kcmconfigs/extensionconfigdialog.cpp b/kaddressbook/kcmconfigs/extensionconfigdialog.cpp
new file mode 100644
index 0000000..e87b000
--- a/dev/null
+++ b/kaddressbook/kcmconfigs/extensionconfigdialog.cpp
@@ -0,0 +1,59 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include <qlayout.h>
+
+#include <klocale.h>
+
+#include "configurewidget.h"
+
+#include "extensionconfigdialog.h"
+
+ExtensionConfigDialog::ExtensionConfigDialog( ExtensionFactory *factory, KConfig *config,
+ QWidget *parent, const char *name )
+ : KDialogBase( Plain, i18n( "Extension Settings" ), Ok | Cancel, Ok, parent,
+ name, true, true ), mWidget( 0 ), mConfig( config )
+{
+ QFrame *page = plainPage();
+ QGridLayout *layout = new QGridLayout( page, 1, 1, marginHint(), spacingHint() );
+
+ mWidget = factory->configureWidget( page, "ExtensionConfigWidget" );
+ layout->addWidget( mWidget, 0, 0 );
+
+ mWidget->restoreSettings( mConfig );
+}
+
+ExtensionConfigDialog::~ExtensionConfigDialog()
+{
+}
+
+void ExtensionConfigDialog::slotOk()
+{
+ mWidget->saveSettings( mConfig );
+
+ KDialogBase::slotOk();
+}
+
+#ifndef KAB_EMBEDDED
+#include "extensionconfigdialog.moc"
+#endif //KAB_EMBEDDED
diff --git a/kaddressbook/kcmconfigs/extensionconfigdialog.h b/kaddressbook/kcmconfigs/extensionconfigdialog.h
new file mode 100644
index 0000000..5a92034
--- a/dev/null
+++ b/kaddressbook/kcmconfigs/extensionconfigdialog.h
@@ -0,0 +1,48 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef EXTENSIONCONFIGDIALOG_H
+#define EXTENSIONCONFIGDIALOG_H
+
+#include <kdialogbase.h>
+
+#include "extensionwidget.h"
+
+class ExtensionConfigDialog : public KDialogBase
+{
+ Q_OBJECT
+
+ public:
+ ExtensionConfigDialog( ExtensionFactory *factory, KConfig *config,
+ QWidget *parent, const char *name = 0 );
+ ~ExtensionConfigDialog();
+
+ protected slots:
+ void slotOk();
+
+ private:
+ ConfigureWidget *mWidget;
+ KConfig *mConfig;
+};
+
+#endif
diff --git a/kaddressbook/kcmconfigs/kabconfigwidget.cpp b/kaddressbook/kcmconfigs/kabconfigwidget.cpp
new file mode 100644
index 0000000..7b3e5c6
--- a/dev/null
+++ b/kaddressbook/kcmconfigs/kabconfigwidget.cpp
@@ -0,0 +1,357 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include <qcheckbox.h>
+#include <qframe.h>
+#include <qgroupbox.h>
+#include <qlayout.h>
+#include <qpushbutton.h>
+#include <qtabwidget.h>
+
+#include <kconfig.h>
+#include <kdebug.h>
+#include <kdialog.h>
+#include <klistview.h>
+#include <klocale.h>
+#include <kglobal.h>
+#include <kmessagebox.h>
+#include <kstandarddirs.h>
+
+#ifndef KAB_EMBEDDED
+#include <ktrader.h>
+#else // KAB_EMBEDDED
+#include <mergewidget.h>
+#include <distributionlistwidget.h>
+#endif // KAB_EMBEDDED
+
+#include "addresseewidget.h"
+#include "extensionconfigdialog.h"
+#include "extensionwidget.h"
+#include "kabprefs.h"
+
+#include "kabconfigwidget.h"
+
+class ExtensionItem : public QCheckListItem
+{
+ public:
+
+#ifndef KAB_EMBEDDED
+ ExtensionItem( QListView *parent, const QString &text );
+ void setService( const KService::Ptr &ptr );
+#else //KAB_EMBEDDED
+ ExtensionItem( QListView *parent, const QString &text, const QString &name, const QString &comment );
+ void setFactory( ExtensionFactory* fac );
+#endif //KAB_EMBEDDED
+
+ bool configWidgetAvailable() const;
+ ExtensionFactory *factory() const;
+
+ virtual QString text( int column ) const;
+
+ private:
+#ifndef KAB_EMBEDDED
+ KService::Ptr mPtr;
+#else //KAB_EMBEDDED
+ ExtensionFactory* mFactory;
+ QString mName;
+ QString mComment;
+
+#endif //KAB_EMBEDDED
+
+};
+
+KABConfigWidget::KABConfigWidget( QWidget *parent, const char *name )
+ : QWidget( parent, name )
+{
+ QVBoxLayout *topLayout = new QVBoxLayout( this, 0,
+ KDialog::spacingHint() );
+
+ QTabWidget *tabWidget = new QTabWidget( this );
+ topLayout->addWidget( tabWidget );
+
+ // General page
+ QWidget *generalPage = new QWidget( this );
+ QVBoxLayout *layout = new QVBoxLayout( generalPage, KDialog::marginHint(),
+ KDialog::spacingHint() );
+
+ QGroupBox *groupBox = new QGroupBox( 0, Qt::Vertical, i18n( "General" ), generalPage );
+ QVBoxLayout *boxLayout = new QVBoxLayout( groupBox->layout() );
+ boxLayout->setAlignment( Qt::AlignTop );
+
+ mViewsSingleClickBox = new QCheckBox( i18n( "Honor KDE single click" ), groupBox, "msingle" );
+ boxLayout->addWidget( mViewsSingleClickBox );
+
+ mNameParsing = new QCheckBox( i18n( "Automatic name parsing for new addressees" ), groupBox, "mparse" );
+ boxLayout->addWidget( mNameParsing );
+
+ layout->addWidget( groupBox );
+
+ groupBox = new QGroupBox( 0, Qt::Vertical, i18n( "Extensions" ), generalPage );
+ boxLayout = new QVBoxLayout( groupBox->layout() );
+ boxLayout->setAlignment( Qt::AlignTop );
+
+ mExtensionView = new KListView( groupBox );
+ mExtensionView->setAllColumnsShowFocus( true );
+ mExtensionView->addColumn( i18n( "Name" ) );
+ mExtensionView->addColumn( i18n( "Description" ) );
+ mExtensionView->setMaximumHeight(80);
+
+ boxLayout->addWidget( mExtensionView );
+
+ mConfigureButton = new QPushButton( i18n( "Configure..." ), groupBox );
+ mConfigureButton->setEnabled( false );
+ boxLayout->addWidget( mConfigureButton );
+
+ layout->addWidget( groupBox );
+
+ connect( mNameParsing, SIGNAL( toggled( bool ) ), this, SLOT( modified() ) );
+ connect( mViewsSingleClickBox, SIGNAL( toggled( bool ) ), this, SLOT( modified() ) );
+ connect( mExtensionView, SIGNAL( selectionChanged( QListViewItem* ) ),
+ SLOT( selectionChanged( QListViewItem* ) ) );
+ connect( mExtensionView, SIGNAL( clicked( QListViewItem* ) ),
+ SLOT( itemClicked( QListViewItem* ) ) );
+ connect( mConfigureButton, SIGNAL( clicked() ),
+ SLOT( configureExtension() ) );
+
+ tabWidget->addTab( generalPage, i18n( "General" ) );
+
+ // Addressee page
+ mAddresseeWidget = new AddresseeWidget( this );
+ tabWidget->addTab( mAddresseeWidget, i18n( "Contact" ) );
+ connect( mAddresseeWidget, SIGNAL( modified() ), SLOT( modified() ) );
+}
+
+void KABConfigWidget::restoreSettings()
+{
+ bool blocked = signalsBlocked();
+ blockSignals( true );
+
+ mNameParsing->setChecked( KABPrefs::instance()->mAutomaticNameParsing );
+ mViewsSingleClickBox->setChecked( KABPrefs::instance()->mHonorSingleClick );
+ mAddresseeWidget->restoreSettings();
+
+ restoreExtensionSettings();
+
+ blockSignals( blocked );
+
+ emit changed( false );
+}
+
+void KABConfigWidget::saveSettings()
+{
+ KABPrefs::instance()->mAutomaticNameParsing = mNameParsing->isChecked();
+ KABPrefs::instance()->mHonorSingleClick = mViewsSingleClickBox->isChecked();
+ mAddresseeWidget->saveSettings();
+
+ saveExtensionSettings();
+ KABPrefs::instance()->writeConfig();
+
+ emit changed( false );
+}
+
+void KABConfigWidget::defaults()
+{
+ mNameParsing->setChecked( true );
+ mViewsSingleClickBox->setChecked( false );
+
+ emit changed( true );
+}
+
+void KABConfigWidget::modified()
+{
+ emit changed( true );
+}
+
+void KABConfigWidget::restoreExtensionSettings()
+{
+ QStringList activeExtensions = KABPrefs::instance()->mActiveExtensions;
+
+ mExtensionView->clear();
+
+#ifndef KAB_EMBEDDED
+ KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/Extension" );
+ KTrader::OfferList::ConstIterator it;
+ for ( it = plugins.begin(); it != plugins.end(); ++it ) {
+ if ( !(*it)->hasServiceType( "KAddressBook/Extension" ) )
+ continue;
+
+ ExtensionItem *item = new ExtensionItem( mExtensionView, (*it)->name() );
+ item->setService( *it );
+ if ( activeExtensions.contains( item->factory()->identifier() ) )
+ item->setOn( true );
+ }
+#else //KAB_EMBEDDED
+ ExtensionFactory *extensionFactory = new MergeFactory();
+
+ ExtensionItem *item = new ExtensionItem( mExtensionView, "Merge", "Merge", "Merge contacts");
+
+ item->setFactory( extensionFactory );
+ if ( activeExtensions.contains( extensionFactory->identifier() ) )
+ item->setOn( true );
+
+
+
+ extensionFactory = new DistributionListFactory();
+
+ item = new ExtensionItem( mExtensionView, "Distribution List", "Distribution List", "Manage Distribution Lists");
+
+ item->setFactory( extensionFactory );
+ if ( activeExtensions.contains( extensionFactory->identifier() ) )
+ item->setOn( true );
+
+
+#endif //KAB_EMBEDDED
+
+}
+
+void KABConfigWidget::saveExtensionSettings()
+{
+ QStringList activeExtensions;
+
+ QPtrList<QListViewItem> list;
+ QListViewItemIterator it( mExtensionView );
+ while ( it.current() ) {
+ ExtensionItem *item = static_cast<ExtensionItem*>( it.current() );
+ if ( item ) {
+ if ( item->isOn() )
+ activeExtensions.append( item->factory()->identifier() );
+ }
+ ++it;
+ }
+
+ KABPrefs::instance()->mActiveExtensions = activeExtensions;
+}
+
+void KABConfigWidget::configureExtension()
+{
+ ExtensionItem *item = static_cast<ExtensionItem*>( mExtensionView->currentItem() );
+ if ( !item )
+ return;
+
+#ifndef KAB_EMBEDDED
+ KConfig config( "kaddressbookrc" );
+#else //KAB_EMBEDDED
+ KConfig config( locateLocal("config", "kaddressbookrc") );
+#endif //KAB_EMBEDDED
+ config.setGroup( QString( "Extensions_%1" ).arg( item->factory()->identifier() ) );
+
+ ExtensionConfigDialog dlg( item->factory(), &config, this );
+ dlg.exec();
+
+ config.sync();
+}
+
+void KABConfigWidget::selectionChanged( QListViewItem *i )
+{
+ ExtensionItem *item = static_cast<ExtensionItem*>( i );
+ if ( !item )
+ return;
+
+ mConfigureButton->setEnabled( item->configWidgetAvailable() );
+}
+
+void KABConfigWidget::itemClicked( QListViewItem *item )
+{
+ if ( item != 0 )
+ modified();
+}
+
+#ifndef KAB_EMBEDDED
+ExtensionItem::ExtensionItem( QListView *parent, const QString &text )
+ : QCheckListItem( parent, text, CheckBox )
+{
+}
+
+void ExtensionItem::setService( const KService::Ptr &ptr )
+{
+ mPtr = ptr;
+}
+#else //KAB_EMBEDDED
+ExtensionItem::ExtensionItem( QListView *parent, const QString &text, const QString &name, const QString &comment )
+ : QCheckListItem( parent, text, CheckBox )
+{
+ mName = name;
+ mComment = comment;
+}
+
+
+void ExtensionItem::setFactory( ExtensionFactory* fac )
+{
+ mFactory = fac;
+}
+#endif //KAB_EMBEDDED
+
+bool ExtensionItem::configWidgetAvailable() const
+{
+#ifndef KAB_EMBEDDED
+ KLibFactory *factory = KLibLoader::self()->factory( mPtr->library().latin1() );
+ if ( !factory )
+ return false;
+
+ ExtensionFactory *extensionFactory = static_cast<ExtensionFactory*>( factory );
+ if ( !extensionFactory )
+ return false;
+
+ return extensionFactory->configureWidgetAvailable();
+#else //KAB_EMBEDDED
+ return mFactory->configureWidgetAvailable();
+#endif //KAB_EMBEDDED
+
+}
+
+ExtensionFactory *ExtensionItem::factory() const
+{
+#ifndef KAB_EMBEDDED
+ KLibFactory *factory = KLibLoader::self()->factory( mPtr->library().latin1() );
+ if ( !factory )
+ return 0;
+
+ return static_cast<ExtensionFactory*>( factory );
+#else //KAB_EMBEDDED
+ return mFactory;
+#endif //KAB_EMBEDDED
+}
+
+QString ExtensionItem::text( int column ) const
+{
+#ifndef KAB_EMBEDDED
+ if ( column == 0 )
+ return mPtr->name();
+ else if ( column == 1 )
+ return mPtr->comment();
+ else
+ return QString::null;
+#else //KAB_EMBEDDED
+ if ( column == 0 )
+ return mName;
+ else if ( column == 1 )
+ return mComment;
+ else
+ return QString::null;
+#endif //KAB_EMBEDDED
+}
+
+#ifndef KAB_EMBEDDED
+#include "kabconfigwidget.moc"
+#endif //KAB_EMBEDDED
+
diff --git a/kaddressbook/kcmconfigs/kabconfigwidget.h b/kaddressbook/kcmconfigs/kabconfigwidget.h
new file mode 100644
index 0000000..0f36d9e
--- a/dev/null
+++ b/kaddressbook/kcmconfigs/kabconfigwidget.h
@@ -0,0 +1,72 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef KABCONFIGWIDGET_H
+#define KABCONFIGWIDGET_H
+
+#include <qwidget.h>
+
+class QCheckBox;
+class QListViewItem;
+class QPushButton;
+
+class KListView;
+
+class AddresseeWidget;
+
+class KABConfigWidget : public QWidget
+{
+ Q_OBJECT
+
+ public:
+ KABConfigWidget( QWidget *parent, const char *name = 0 );
+
+ void restoreSettings();
+ void saveSettings();
+ void defaults();
+
+ signals:
+ void changed( bool );
+
+ public slots:
+ void modified();
+
+ private slots:
+ void configureExtension();
+ void selectionChanged( QListViewItem* );
+ void itemClicked( QListViewItem* );
+
+ private:
+ void restoreExtensionSettings();
+ void saveExtensionSettings();
+
+ KListView *mExtensionView;
+
+ QCheckBox *mNameParsing;
+ QCheckBox *mViewsSingleClickBox;
+ QPushButton *mConfigureButton;
+
+ AddresseeWidget *mAddresseeWidget;
+};
+
+#endif
diff --git a/kaddressbook/kcmconfigs/kcmkabconfig.cpp b/kaddressbook/kcmconfigs/kcmkabconfig.cpp
new file mode 100644
index 0000000..791a940
--- a/dev/null
+++ b/kaddressbook/kcmconfigs/kcmkabconfig.cpp
@@ -0,0 +1,86 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include <qlayout.h>
+
+#ifndef KAB_EMBEDDED
+#include <kaboutdata.h>
+#endif //KAB_EMBEDDED
+#include <kdebug.h>
+#include <klocale.h>
+
+#include "kabconfigwidget.h"
+
+#include "kcmkabconfig.h"
+
+extern "C"
+{
+ KCModule *create_kabconfig( QWidget *parent, const char * ) {
+ return new KCMKabConfig( parent, "kcmkabconfig" );
+ }
+}
+
+KCMKabConfig::KCMKabConfig( QWidget *parent, const char *name )
+ : KCModule( parent, name )
+{
+ QVBoxLayout *layout = new QVBoxLayout( this );
+ mConfigWidget = new KABConfigWidget( this, "mConfigWidget" );
+ layout->addWidget( mConfigWidget );
+
+ connect( mConfigWidget, SIGNAL( changed( bool ) ), SIGNAL( changed( bool ) ) );
+ load();
+}
+
+void KCMKabConfig::load()
+{
+ mConfigWidget->restoreSettings();
+}
+
+void KCMKabConfig::save()
+{
+ mConfigWidget->saveSettings();
+}
+
+void KCMKabConfig::defaults()
+{
+ mConfigWidget->defaults();
+}
+
+#ifndef KAB_EMBEDDED
+const KAboutData* KCMKabConfig::aboutData() const
+{
+ KAboutData *about = new KAboutData( I18N_NOOP( "kcmkabconfig" ),
+ I18N_NOOP( "KAddressBook Configure Dialog" ),
+ 0, 0, KAboutData::License_GPL,
+ I18N_NOOP( "(c), 2003 Tobias Koenig" ) );
+
+ about->addAuthor( "Tobias Koenig", 0, "tokoe@kde.org" );
+
+ return about;
+
+}
+#endif //KAB_EMBEDDED
+
+#ifndef KAB_EMBEDDED
+#include "kcmkabconfig.moc"
+#endif //KAB_EMBEDDED
diff --git a/kaddressbook/kcmconfigs/kcmkabconfig.h b/kaddressbook/kcmconfigs/kcmkabconfig.h
new file mode 100644
index 0000000..be345b8
--- a/dev/null
+++ b/kaddressbook/kcmconfigs/kcmkabconfig.h
@@ -0,0 +1,53 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef KCMKABCONFIG_H
+#define KCMKABCONFIG_H
+
+#include <kcmodule.h>
+
+class KABConfigWidget;
+
+#ifndef KAB_EMBEDDED
+class KAboutData;
+#endif //KAB_EMBEDDED
+
+class KCMKabConfig : public KCModule
+{
+ Q_OBJECT
+
+ public:
+ KCMKabConfig( QWidget *parent = 0, const char *name = 0 );
+
+ virtual void load();
+ virtual void save();
+ virtual void defaults();
+#ifndef KAB_EMBEDDED
+ virtual const KAboutData* aboutData() const;
+#endif //KAB_EMBEDDED
+
+ private:
+ KABConfigWidget *mConfigWidget;
+};
+
+#endif
diff --git a/kaddressbook/keywidget.cpp b/kaddressbook/keywidget.cpp
new file mode 100644
index 0000000..c117d34
--- a/dev/null
+++ b/kaddressbook/keywidget.cpp
@@ -0,0 +1,277 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include <qfile.h>
+
+#include <qinputdialog.h>
+
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qpushbutton.h>
+
+#ifndef KAB_EMBEDDED
+#include <kaccelmanager.h>
+#include <kio/netaccess.h>
+#include <kmessagebox.h>
+#else //KAB_EMBEDDED
+#include <qmap.h>
+#include <qmessagebox.h>
+#include <qtextstream.h>
+#include <kurl.h>
+#endif //KAB_EMBEDDED
+
+#include <kapplication.h>
+#include <kcombobox.h>
+#include <kdialog.h>
+#include <kfiledialog.h>
+#include <klocale.h>
+#include <ktempfile.h>
+
+#include "keywidget.h"
+
+KeyWidget::KeyWidget( QWidget *parent, const char *name )
+ : QWidget( parent, name )
+{
+ QGridLayout *layout = new QGridLayout( this, 2, 2, KDialog::marginHint(),
+ KDialog::spacingHint() );
+
+ QLabel *label = new QLabel( i18n( "Keys:" ), this );
+ layout->addWidget( label, 0, 0 );
+
+ mKeyCombo = new KComboBox( this );
+ layout->addWidget( mKeyCombo, 0, 1 );
+
+ mAddButton = new QPushButton( i18n( "Add" ), this );
+ layout->addWidget( mAddButton, 1, 0 );
+
+ mRemoveButton = new QPushButton( i18n( "Remove" ), this );
+ mRemoveButton->setEnabled( false );
+ layout->addWidget( mRemoveButton, 1, 1 );
+
+ mExportButton = new QPushButton( i18n( "Export" ), this );
+ mExportButton->setEnabled( false );
+ layout->addMultiCellWidget( mExportButton, 2, 2, 0, 1 );
+
+ connect( mAddButton, SIGNAL( clicked() ), SLOT( addKey() ) );
+ connect( mRemoveButton, SIGNAL( clicked() ), SLOT( removeKey() ) );
+ connect( mExportButton, SIGNAL( clicked() ), SLOT( exportKey() ) );
+}
+
+KeyWidget::~KeyWidget()
+{
+}
+
+void KeyWidget::setKeys( const KABC::Key::List &list )
+{
+ mKeyList = list;
+
+ updateKeyCombo();
+}
+
+KABC::Key::List KeyWidget::keys() const
+{
+ return mKeyList;
+}
+
+void KeyWidget::addKey()
+{
+ QMap<QString, int> keyMap;
+ QStringList keyTypeNames;
+ QStringList existingKeyTypes;
+
+ KABC::Key::List::Iterator listIt;
+ for ( listIt = mKeyList.begin(); listIt != mKeyList.end(); ++listIt ) {
+ if ( (*listIt).type() != KABC::Key::Custom )
+ existingKeyTypes.append( KABC::Key::typeLabel( (*listIt).type() ) );
+ }
+
+ KABC::Key::TypeList typeList = KABC::Key::typeList();
+ KABC::Key::TypeList::Iterator it;
+ for ( it = typeList.begin(); it != typeList.end(); ++it ) {
+ if ( (*it) != KABC::Key::Custom &&
+ !existingKeyTypes.contains( KABC::Key::typeLabel( *it ) ) ) {
+ keyMap.insert( KABC::Key::typeLabel( *it ), *it );
+ keyTypeNames.append( KABC::Key::typeLabel( *it ) );
+ }
+ }
+
+ bool ok;
+ QString name = QInputDialog::getItem( i18n( "Key type" ), i18n( "Select the key type." ), keyTypeNames, 0, true, &ok );
+
+
+
+ if ( !ok || name.isEmpty() )
+ return;
+
+ int type = keyMap[ name ];
+ if ( !keyTypeNames.contains( name ) )
+ type = KABC::Key::Custom;
+
+#ifndef KAB_EMBEDDED
+ KURL url = KFileDialog::getOpenURL();
+
+ if ( url.isEmpty() )
+ return;
+
+ QString tmpFile;
+ if ( KIO::NetAccess::download( url, tmpFile ) ) {
+ QFile file( tmpFile );
+ if ( !file.open( IO_ReadOnly ) ) {
+ QString text( i18n( "<qt>Unable to open file <b>%1</b>.</qt>" ) );
+ KMessageBox::error( this, text.arg( url.url() ) );
+ return;
+ }
+
+
+#else //KAB_EMBEDDED
+ QString keyfile = KFileDialog::getOpenFileName( "huhu",
+ "Select Key", this );
+
+ if ( keyfile.isEmpty() )
+ return;
+
+ {
+ QFile file( keyfile );
+ if ( !file.open( IO_ReadOnly ) ) {
+ QString text( i18n( "<qt>Unable to open file <b>%1</b>.</qt>" ) );
+ QString caption( i18n( "Error" ) );
+ QMessageBox::critical( this, caption, text.arg( keyfile ) );
+ return;
+ }
+
+#endif //KAB_EMBEDDED
+
+
+
+ QTextStream s( &file );
+ QString data;
+
+ s.setEncoding( QTextStream::UnicodeUTF8 );
+ s >> data;
+ file.close();
+
+ KABC::Key key( data, type );
+ if ( type == KABC::Key::Custom )
+ key.setCustomTypeString( name );
+ mKeyList.append( key );
+
+ emit changed();
+
+#ifndef KAB_EMBEDDED
+ KIO::NetAccess::removeTempFile( tmpFile );
+#endif //KAB_EMBEDDED
+
+ }
+
+ updateKeyCombo();
+}
+
+void KeyWidget::removeKey()
+{
+ int pos = mKeyCombo->currentItem();
+ if ( pos == -1 )
+ return;
+
+ QString type = mKeyCombo->currentText();
+ QString text = i18n( "<qt>Do you really want to remove the key <b>%1</b>?</qt>" );
+
+
+#ifndef KAB_EMBEDDED
+ if ( KMessageBox::questionYesNo( this, text.arg( type ) ) == KMessageBox::No )
+ return;
+#else //KAB_EMBEDDED
+ QString caption = i18n( "Confirm Delete" );
+ if (QMessageBox::information( this, caption,
+ text.arg( type ),
+ i18n("Yes!"), i18n("No"), 0, 0 ) == 1)
+ return;
+#endif //KAB_EMBEDDED
+
+ mKeyList.remove( mKeyList.at( pos ) );
+ emit changed();
+
+ updateKeyCombo();
+}
+
+void KeyWidget::exportKey()
+{
+ KABC::Key key = (*mKeyList.at( mKeyCombo->currentItem() ) );
+
+#ifndef KAB_EMBEDDED
+ KURL url = KFileDialog::getSaveURL();
+
+ KTempFile tempFile;
+ QTextStream *s = tempFile.textStream();
+ s->setEncoding( QTextStream::UnicodeUTF8 );
+ (*s) << key.textData();
+ tempFile.close();
+
+ KIO::NetAccess::upload( tempFile.name(), url, kapp->mainWidget() );
+#else //KAB_EMBEDDED
+ QString keyfile = KFileDialog::getSaveFileName( "huhu",
+ "Save Key", this );
+
+ if ( keyfile.isEmpty() )
+ return;
+
+ QFile file( keyfile );
+ if ( !file.open( IO_ReadWrite ) ) {
+ QString text( i18n( "<qt>Unable to open file <b>%1</b>.</qt>" ) );
+ QString caption( i18n( "Error" ) );
+ QMessageBox::critical( this, caption, text.arg( keyfile ) );
+ return;
+ }
+
+ QTextStream s( &file );
+ s.setEncoding( QTextStream::UnicodeUTF8 );
+ s << key.textData();
+ file.close();
+
+
+#endif //KAB_EMBEDDED
+
+}
+
+void KeyWidget::updateKeyCombo()
+{
+ int pos = mKeyCombo->currentItem();
+ mKeyCombo->clear();
+
+ KABC::Key::List::Iterator it;
+ for ( it = mKeyList.begin(); it != mKeyList.end(); ++it ) {
+ if ( (*it).type() == KABC::Key::Custom )
+ mKeyCombo->insertItem( (*it).customTypeString() );
+ else
+ mKeyCombo->insertItem( KABC::Key::typeLabel( (*it).type() ) );
+ }
+
+ mKeyCombo->setCurrentItem( pos );
+
+ bool state = ( mKeyList.count() != 0 );
+ mRemoveButton->setEnabled( state );
+ mExportButton->setEnabled( state );
+}
+
+#ifndef KAB_EMBEDDED
+#include "keywidget.moc"
+#endif //KAB_EMBEDDED
diff --git a/kaddressbook/keywidget.h b/kaddressbook/keywidget.h
new file mode 100644
index 0000000..50bac53
--- a/dev/null
+++ b/kaddressbook/keywidget.h
@@ -0,0 +1,65 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef KEYWIDGET_H
+#define KEYWIDGET_H
+
+#include <qwidget.h>
+#include <kabc/key.h>
+
+class KComboBox;
+
+class QPushButton;
+
+class KeyWidget : public QWidget
+{
+ Q_OBJECT
+
+ public:
+ KeyWidget( QWidget *parent, const char *name = 0 );
+ ~KeyWidget();
+
+ void setKeys( const KABC::Key::List &list );
+ KABC::Key::List keys() const;
+
+ signals:
+ void changed();
+
+ private slots:
+ void addKey();
+ void removeKey();
+ void exportKey();
+
+ private:
+ void updateKeyCombo();
+
+ KComboBox *mKeyCombo;
+
+ QPushButton *mAddButton;
+ QPushButton *mRemoveButton;
+ QPushButton *mExportButton;
+
+ KABC::Key::List mKeyList;
+};
+
+#endif
diff --git a/kaddressbook/mainembedded.cpp b/kaddressbook/mainembedded.cpp
new file mode 100644
index 0000000..ffa37a5
--- a/dev/null
+++ b/kaddressbook/mainembedded.cpp
@@ -0,0 +1,208 @@
+#ifndef DESKTOP_VERSION
+#include <qpe/qpeapplication.h>
+#include <qpe/global.h>
+#include <stdlib.h>
+#else
+#include <qapplication.h>
+#include <qwindowsstyle.h>
+#include <qplatinumstyle.h>
+#include <qmainwindow.h>
+#endif
+
+#include <kstandarddirs.h>
+#include <kglobal.h>
+#include <stdio.h>
+#include <qdir.h>
+#include "kaddressbookmain.h"
+
+int main( int argc, char **argv )
+{
+#ifndef DESKTOP_VERSION
+ QPEApplication a( argc, argv );
+ a.setKeepRunning ();
+#else
+ QApplication a( argc, argv );
+ QApplication::setStyle( new QPlatinumStyle ());
+#endif
+
+ bool exitHelp = false;
+ if ( argc > 1 ) {
+ QString command = argv[1];
+ if ( command == "-help" ){
+ printf("KA/E command line commands:\n");
+ printf(" no command: Start KA/E in usual way\n");
+ printf(" -help: This output\n");
+ printf(" KA/E is exiting now. Bye!\n");
+ exitHelp = true;
+ }
+ }
+ if ( ! exitHelp ) {
+
+ KGlobal::setAppName( "kaddressbook" );
+#ifndef DESKTOP_VERSION
+ KStandardDirs::setAppDir( Global::applicationFileName( "kaddressbook", "" ) );
+ KGlobal::iconLoader()->setIconPath(QString(getenv("QPEDIR"))+"/pics/kdepim/kaddressbook/icons16/");
+#else
+ QString fileName ;
+#ifndef _WIN32_
+ fileName = qApp->applicationDirPath () + "/kdepim/kaddressbook/icons16/";
+#else
+ fileName = qApp->applicationDirPath () + "\\kdepim\\kaddressbook\\icons16\\";
+#endif
+ KGlobal::iconLoader()->setIconPath(fileName);
+ QString appdir = QDir::homeDirPath();
+ if ( appdir.right(1) == "\\" || appdir.right(1) == "/" )
+ appdir += "kaddressbook";
+ else
+ appdir += "/kaddressbook";
+ KStandardDirs::setAppDir( QDir::convertSeparators( appdir ));
+ // qDebug(" %s ",KStandardDirs::appDir().latin1() );
+#endif // desktop
+ QDir app_dir;
+ if ( !app_dir.exists(KStandardDirs::appDir()) )
+ app_dir.mkdir (KStandardDirs::appDir());
+
+ KAddressBookMain* m = new KAddressBookMain();
+//US MainWindow m;
+//US QObject::connect( &a, SIGNAL (appMessage ( const QCString &, const QByteArray & )),&m, SLOT(recieve( const QCString&, const QByteArray& )));
+
+#ifndef DESKTOP_VERSION
+ a.showMainWidget(m );
+ m->showFullScreen();
+ int min = 20;
+ if ( QApplication::desktop()->width() > 320 )
+ min += 20;
+ m->setGeometry( 0,0,QApplication::desktop()->width(), QApplication::desktop()->height() - min );
+
+#else
+ a.setMainWidget(m );
+ m->show();
+ //m->resize( 640, 480 );
+#endif
+ a.exec();
+
+ }
+ qDebug("KA: Bye! ");
+}
+
+/*
+#include <stdlib.h>
+
+#include <qstring.h>
+
+#include <kabc/stdaddressbook.h>
+#include <kaboutdata.h>
+#include <kcmdlineargs.h>
+#include <kcrash.h>
+#include <kdebug.h>
+#include <klocale.h>
+#include <kstartupinfo.h>
+#include <kuniqueapplication.h>
+#include <kwin.h>
+
+#include "kaddressbookmain.h"
+#include "kabcore.h"
+
+extern "C" {
+
+void crashHandler( int )
+{
+ KABC::StdAddressBook::handleCrash();
+ ::exit( 0 );
+}
+
+}
+
+class KAddressBookApp : public KUniqueApplication {
+ public:
+ KAddressBookApp() : mMainWin( 0 ) {}
+ ~KAddressBookApp() {}
+
+ int newInstance();
+
+ private:
+ KAddressBookMain *mMainWin;
+};
+
+int KAddressBookApp::newInstance()
+{
+ if ( isRestored() ) {
+ // There can only be one main window
+ if ( KMainWindow::canBeRestored( 1 ) ) {
+ mMainWin = new KAddressBookMain;
+ mMainWin->show();
+ mMainWin->restore( 1 );
+ }
+ } else {
+ KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
+
+ QCString addrStr = args->getOption( "addr" );
+ QCString uidStr = args->getOption( "uid" );
+ QString addr;
+ QString uid;
+ if ( !addrStr.isEmpty() )
+ addr = QString::fromLocal8Bit( addrStr );
+ if ( !uidStr.isEmpty() )
+ uid = QString::fromLocal8Bit( uidStr );
+
+
+ if ( args->isSet( "editor-only" ) ) {
+ if ( !mMainWin )
+ mMainWin = new KAddressBookMain;
+ KStartupInfo::appStarted();
+ mMainWin->hide();
+ } else {
+ if ( mMainWin ) {
+ mMainWin->show();
+ KWin::setActiveWindow( mMainWin->winId() );
+ } else {
+ mMainWin = new KAddressBookMain;
+ mMainWin->show();
+ }
+ }
+ // Can not see why anyone would pass both a uid and an email address, so I'll leave it that two contact editors will show if they do
+ if ( !addr.isEmpty() )
+ mMainWin->addEmail( addr );
+
+ if ( !uid.isEmpty() )
+ mMainWin->showContactEditor( uid );
+ if ( args->isSet( "new-contact" ) ) {
+ mMainWin->newContact();
+ }
+ }
+
+ KCrash::setEmergencySaveFunction( crashHandler );
+
+ return 0;
+}
+
+// the dummy argument is required, because KMail apparently sends an empty
+// argument.
+static KCmdLineOptions kmoptions[] =
+{
+ { "a", 0 , 0 },
+ { "addr <email>", I18N_NOOP( "Shows contact editor with given email address" ), 0 },
+ { "uid <uid>", I18N_NOOP( "Shows contact editor with given uid" ), 0 },
+ { "editor-only", I18N_NOOP( "Launches in editor only mode" ), 0 },
+ { "new-contact", I18N_NOOP( "Launches editor for the new contact" ), 0 },
+ { "+[argument]", I18N_NOOP( "dummy argument" ), 0},
+ { 0, 0, 0}
+};
+
+int main( int argc, char *argv[] )
+{
+ KLocale::setMainCatalogue( "kaddressbook" );
+
+ KCmdLineArgs::init( argc, argv, KABCore::createAboutData() );
+ KCmdLineArgs::addCmdLineOptions( kmoptions );
+ KUniqueApplication::addCmdLineOptions();
+
+ if ( !KAddressBookApp::start() )
+ exit( 0 );
+
+ KAddressBookApp app;
+ KGlobal::locale()->insertCatalogue( "libkdepim" );
+
+ return app.exec();
+}
+*/
diff --git a/kaddressbook/nameeditdialog.cpp b/kaddressbook/nameeditdialog.cpp
new file mode 100644
index 0000000..fb7eb22
--- a/dev/null
+++ b/kaddressbook/nameeditdialog.cpp
@@ -0,0 +1,296 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include <qlayout.h>
+#include <qlabel.h>
+#include <qlistbox.h>
+#include <qlistview.h>
+#include <qtooltip.h>
+#include <qpushbutton.h>
+#include <qcheckbox.h>
+#include <qstring.h>
+
+#ifndef KAB_EMBEDDED
+#include <kaccelmanager.h>
+#else //KAB_EMBEDDED
+#include <kstandarddirs.h>
+#endif //KAB_EMBEDDED
+
+#include <kapplication.h>
+#include <kbuttonbox.h>
+#include <kconfig.h>
+#include <klineedit.h>
+#include <klistview.h>
+#include <kcombobox.h>
+#include <klocale.h>
+#include <kglobal.h>
+#include <kdebug.h>
+#include <kiconloader.h>
+#include <kmessagebox.h>
+
+#include "nameeditdialog.h"
+
+NameEditDialog::NameEditDialog( const KABC::Addressee &addr, int type,
+ QWidget *parent, const char *name )
+ : KDialogBase( Plain, i18n( "Edit Contact Name" ), Help | Ok | Cancel,
+ Ok, parent, name, true )
+{
+
+ QWidget *page = plainPage();
+ QGridLayout *layout = new QGridLayout( page, 5, 3 );
+ layout->setSpacing( spacingHint() );
+ layout->addColSpacing( 2, 100 );
+ QLabel *label;
+
+ label = new QLabel( i18n( "Honorific prefixes:" ), page );
+ layout->addWidget( label, 0, 0 );
+ mPrefixCombo = new KComboBox( page );
+ mPrefixCombo->setDuplicatesEnabled( false );
+ mPrefixCombo->setEditable( true );
+ label->setBuddy( mPrefixCombo );
+ layout->addMultiCellWidget( mPrefixCombo, 0, 0, 1, 2 );
+
+ label = new QLabel( i18n( "Given name:" ), page );
+ layout->addWidget( label, 1, 0 );
+ mGivenNameEdit = new KLineEdit( page );
+ label->setBuddy( mGivenNameEdit );
+ layout->addMultiCellWidget( mGivenNameEdit, 1, 1, 1, 2 );
+
+ label = new QLabel( i18n( "Additional names:" ), page );
+ layout->addWidget( label, 2, 0 );
+ mAdditionalNameEdit = new KLineEdit( page );
+ label->setBuddy( mAdditionalNameEdit );
+ layout->addMultiCellWidget( mAdditionalNameEdit, 2, 2, 1, 2 );
+
+ label = new QLabel( i18n( "Family names:" ), page );
+ layout->addWidget( label, 3, 0 );
+ mFamilyNameEdit = new KLineEdit( page );
+ label->setBuddy( mFamilyNameEdit );
+ layout->addMultiCellWidget( mFamilyNameEdit, 3, 3, 1, 2 );
+
+ label = new QLabel( i18n( "Honorific suffixes:" ), page );
+ layout->addWidget( label, 4, 0 );
+ mSuffixCombo = new KComboBox( page );
+ mSuffixCombo->setDuplicatesEnabled( false );
+ mSuffixCombo->setEditable( true );
+ label->setBuddy( mSuffixCombo );
+ layout->addMultiCellWidget( mSuffixCombo, 4, 4, 1, 2 );
+
+ mFormattedNameCombo = new KComboBox( page );
+ mFormattedNameCombo->setMaximumWidth(100);
+
+ layout->addMultiCellWidget( mFormattedNameCombo, 5, 5, 0, 0 );
+ connect( mFormattedNameCombo, SIGNAL( activated( int ) ), SLOT( typeChanged( int ) ) );
+
+ mFormattedNameEdit = new KLineEdit( page );
+ mFormattedNameEdit->setEnabled( type == CustomName );
+ layout->addMultiCellWidget( mFormattedNameEdit, 5, 5, 1, 2 );
+
+ mParseBox = new QCheckBox( i18n( "Parse name automatically" ), page );
+ connect( mParseBox, SIGNAL( toggled(bool) ), SLOT( parseBoxChanged(bool) ) );
+ connect( mParseBox, SIGNAL( toggled(bool) ), SLOT( modified() ) );
+ layout->addMultiCellWidget( mParseBox, 6, 6, 0, 1 );
+
+ // Fill in the values
+ mFamilyNameEdit->setText( addr.familyName() );
+ mGivenNameEdit->setText( addr.givenName() );
+ mAdditionalNameEdit->setText( addr.additionalName() );
+ mFormattedNameEdit->setText( addr.formattedName() );
+
+ // Prefix and suffix combos
+//US KConfig config( "kabcrc" );
+ KConfig config( locateLocal("config", "kabcrc") );
+ config.setGroup( "General" );
+
+ QStringList sTitle;
+ sTitle += i18n( "Dr." );
+ sTitle += i18n( "Miss" );
+ sTitle += i18n( "Mr." );
+ sTitle += i18n( "Mrs." );
+ sTitle += i18n( "Ms." );
+ sTitle += i18n( "Prof." );
+ sTitle += config.readListEntry( "Prefixes" );
+ sTitle.sort();
+
+ QStringList sSuffix;
+ sSuffix += i18n( "I" );
+ sSuffix += i18n( "II" );
+ sSuffix += i18n( "III" );
+ sSuffix += i18n( "Jr." );
+ sSuffix += i18n( "Sr." );
+ sSuffix += config.readListEntry( "Suffixes" );
+ sSuffix.sort();
+
+ mPrefixCombo->insertStringList( sTitle );
+ mSuffixCombo->insertStringList( sSuffix );
+
+#ifndef KAB_EMBEDDED
+ mPrefixCombo->setCurrentText( addr.prefix() );
+ mSuffixCombo->setCurrentText( addr.suffix() );
+#else //KAB_EMBEDDED
+ mPrefixCombo->setEditText( addr.prefix() );
+ mSuffixCombo->setEditText( addr.suffix() );
+#endif //KAB_EMBEDDED
+
+ AddresseeConfig::instance()->setUid( addr.uid() );
+ mParseBox->setChecked( AddresseeConfig::instance()->automaticNameParsing() );
+
+#ifndef KAB_EMBEDDED
+ KAcceleratorManager::manage( this );
+#endif //KAB_EMBEDDED
+
+ connect( mPrefixCombo, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) );
+ connect( mPrefixCombo, SIGNAL( textChanged( const QString& ) ), SLOT( updateTypeCombo() ) );
+ connect( mGivenNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) );
+ connect( mGivenNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( updateTypeCombo() ) );
+ connect( mAdditionalNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) );
+ connect( mAdditionalNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( updateTypeCombo() ) );
+ connect( mFamilyNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) );
+ connect( mFamilyNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( updateTypeCombo() ) );
+ connect( mSuffixCombo, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) );
+ connect( mSuffixCombo, SIGNAL( textChanged( const QString& ) ), SLOT( updateTypeCombo() ) );
+ connect( mFormattedNameCombo, SIGNAL( activated( int ) ), SLOT( modified() ) );
+ connect( mFormattedNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) );
+
+ updateTypeCombo();
+ mFormattedNameCombo->setCurrentItem( type );
+
+#ifdef KAB_EMBEDDED
+ resize( KMIN(KGlobal::getDesktopWidth()-10, 490), KMIN(KGlobal::getDesktopHeight()-50, 300));
+#endif //KAB_EMBEDDED
+
+ mChanged = false;
+}
+
+NameEditDialog::~NameEditDialog()
+{
+}
+
+QString NameEditDialog::familyName() const
+{
+ return mFamilyNameEdit->text();
+}
+
+QString NameEditDialog::givenName() const
+{
+ return mGivenNameEdit->text();
+}
+
+QString NameEditDialog::prefix() const
+{
+ return mPrefixCombo->currentText();
+}
+
+QString NameEditDialog::suffix() const
+{
+ return mSuffixCombo->currentText();
+}
+
+QString NameEditDialog::additionalName() const
+{
+ return mAdditionalNameEdit->text();
+}
+
+QString NameEditDialog::customFormattedName() const
+{
+ return mFormattedNameEdit->text();
+}
+
+int NameEditDialog::formattedNameType() const
+{
+ return mFormattedNameCombo->currentItem();
+}
+
+bool NameEditDialog::changed() const
+{
+ return mChanged;
+}
+
+QString NameEditDialog::formattedName( const KABC::Addressee &addr, int type )
+{
+ switch ( type ) {
+ case SimpleName:
+ return addr.givenName() + " " + addr.familyName();
+ break;
+ case FullName:
+ return addr.prefix() + " " + addr.givenName() + " " +
+ addr.additionalName() + " " + addr.familyName() + " " +
+ addr.suffix();
+ break;
+ case ReverseName:
+ return addr.familyName() + ", " + addr.givenName();
+ break;
+ default:
+ return "";
+ break;
+ }
+}
+
+void NameEditDialog::parseBoxChanged( bool value )
+{
+ //AddresseeConfig::instance()->setUid( addr.uid() );
+ AddresseeConfig::instance()->setAutomaticNameParsing( value );
+}
+
+void NameEditDialog::typeChanged( int pos )
+{
+ mFormattedNameEdit->setEnabled( pos == 0 );
+}
+
+void NameEditDialog::modified()
+{
+ mChanged = true;
+}
+
+void NameEditDialog::updateTypeCombo()
+{
+ KABC::Addressee addr;
+ addr.setPrefix( mPrefixCombo->currentText() );
+ addr.setGivenName( mGivenNameEdit->text() );
+ addr.setAdditionalName( mAdditionalNameEdit->text() );
+ addr.setFamilyName( mFamilyNameEdit->text() );
+ addr.setSuffix( mSuffixCombo->currentText() );
+
+ int pos = mFormattedNameCombo->currentItem();
+
+ mFormattedNameCombo->clear();
+ mFormattedNameCombo->insertItem( i18n( "Custom" ) );
+ mFormattedNameCombo->insertItem( formattedName( addr, SimpleName ) );
+ mFormattedNameCombo->insertItem( formattedName( addr, FullName ) );
+ mFormattedNameCombo->insertItem( formattedName( addr, ReverseName ) );
+
+ mFormattedNameCombo->setCurrentItem( pos );
+}
+
+void NameEditDialog::slotHelp()
+{
+#ifndef KAB_EMBEDDED
+ kapp->invokeHelp( "managing-contacts-automatic-nameparsing" );
+#else //KAB_EMBEDDED
+qDebug("NameEditDialog::slotHelp Help is not supported yet");
+#endif //KAB_EMBEDDED
+}
+
+#ifndef KAB_EMBEDDED
+#include "nameeditdialog.moc"
+#endif //KAB_EMBEDDED
diff --git a/kaddressbook/nameeditdialog.h b/kaddressbook/nameeditdialog.h
new file mode 100644
index 0000000..1d756c1
--- a/dev/null
+++ b/kaddressbook/nameeditdialog.h
@@ -0,0 +1,90 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef NAMEEDITDIALOG_H
+#define NAMEEDITDIALOG_H
+
+#include <kdialogbase.h>
+#include <kabc/addressee.h>
+
+#include "addresseeconfig.h"
+
+class QCheckBox;
+
+class KLineEdit;
+class KComboBox;
+
+/**
+ Editor dialog for name details, like given name, family name etc.
+*/
+class NameEditDialog : public KDialogBase
+{
+ Q_OBJECT
+
+ public:
+ enum FormattedNameType
+ {
+ CustomName, // returned by @ref customFormattedName()
+ SimpleName, // form: givenName familyName
+ FullName, // form: prefix givenName additionalName familyName suffix
+ ReverseName // form: familyName, givenName
+ };
+
+ NameEditDialog( const KABC::Addressee &addr, int type,
+ QWidget *parent, const char *name = 0 );
+ ~NameEditDialog();
+
+ QString familyName() const;
+ QString givenName() const;
+ QString prefix() const;
+ QString suffix() const;
+ QString additionalName() const;
+ QString customFormattedName() const;
+ int formattedNameType() const;
+
+ bool changed() const;
+
+ static QString formattedName( const KABC::Addressee &addr, int type );
+
+ protected slots:
+ void slotHelp();
+
+ private slots:
+ void parseBoxChanged( bool );
+ void typeChanged( int );
+ void updateTypeCombo();
+ void modified();
+
+ private:
+ KComboBox *mSuffixCombo;
+ KComboBox *mPrefixCombo;
+ KComboBox *mFormattedNameCombo;
+ KLineEdit *mFamilyNameEdit;
+ KLineEdit *mGivenNameEdit;
+ KLineEdit *mAdditionalNameEdit;
+ KLineEdit *mFormattedNameEdit;
+ QCheckBox *mParseBox;
+ bool mChanged;
+};
+
+#endif
diff --git a/kaddressbook/old_mainwindow.cpp b/kaddressbook/old_mainwindow.cpp
new file mode 100644
index 0000000..0e886d9
--- a/dev/null
+++ b/kaddressbook/old_mainwindow.cpp
@@ -0,0 +1,1561 @@
+#include <qlabel.h>
+#include <qapp.h>
+#include <qmessagebox.h>
+#include <qaction.h>
+
+#include <kdebug.h> // defined kdDebug()
+#include <klocale.h> // defines i18n (microkde)
+
+#include "kabprefs.h"
+
+#ifndef DESKTOP_VERSION
+#include <qpe/qpetoolbar.h>
+#include <qpe/qpemenubar.h>
+#include <qpe/resource.h>
+#else
+#include <qtoolbar.h>
+#include <qmenubar.h>
+#include <resource.h>
+#endif
+
+/*
+#include <stdlib.h>
+
+#include <qaction.h>
+#include <qpainter.h>
+#include <qwhatsthis.h>
+#include <qpopupmenu.h>
+#include <qmessagebox.h>
+#include <qlineedit.h>
+#include <qfile.h>
+#include <qfileinfo.h>
+#include <qwmatrix.h>
+#ifndef DESKTOP_VERSION
+#include <qpe/global.h>
+#include <qpe/qpemenubar.h>
+#include <qpe/qpetoolbar.h>
+#include <qpe/resource.h>
+#include <qpe/qpeapplication.h>
+#include <qtopia/alarmserver.h>
+#include <qtopia/qcopenvelope_qws.h>
+#else
+#include <qtoolbar.h>
+#include <qdir.h>
+#include <qapplication.h>
+//#include <resource.h>
+#endif
+
+#include <libkcal/calendarlocal.h>
+#include <libkcal/todo.h>
+
+//#include "calendarview.h"
+//#include "koviewmanager.h"
+//#include "koagendaview.h"
+//#include "kodialogmanager.h"
+//#include "kdialogbase.h"
+//#include "koprefs.h"
+//#include "kfiledialog.h"
+//#include "koglobals.h"
+
+//#include "kconfig.h"
+//#include "simplealarmclient.h"
+*/
+//US using namespace KACore;
+
+
+#include "mainwindow.h"
+
+MainWindow::MainWindow( QWidget *parent, const char *name, QString msg) :
+ QMainWindow( parent, name )
+{
+
+#ifdef DESKTOP_VERSION
+ setFont( QFont("Arial"), 14 );
+#endif
+// mBlockAtStartup = true;
+ kdDebug() << "MainWindow()::MainWindow()" << endl;
+// mFlagKeyPressed = false;
+ setCaption("KAddressbook/Pi");
+
+ KABPrefs *p = KABPrefs::instance();
+ if ( QApplication::desktop()->height() > 480 ) {
+//US if ( p->mHourSize == 4 )
+//US p->mHourSize = 6;
+ }
+
+ QMainWindow::ToolBarDock tbd;
+ if ( p->mToolBarHor ) {
+ if ( p->mToolBarUp )
+ tbd = Bottom;
+ else
+ tbd = Top;
+ }
+ else {
+ if ( p->mToolBarUp )
+ tbd = Right;
+ else
+ tbd = Left;
+ }
+
+ iconToolBar = new QPEToolBar( this );
+ addToolBar (iconToolBar , tbd );
+
+/*US
+ mBlockSaveFlag = false;
+ mCalendarModifiedFlag = false;
+*/
+ QLabel* splash = new QLabel(i18n("KA/Pi is starting ... "), this );
+ splash->setAlignment ( AlignCenter );
+ setCentralWidget( splash );
+#ifndef DESKTOP_VERSION
+ showMaximized();
+#endif
+ qDebug("Mainwidget x %d y %d w %d h %d", x(), y(), width(), height ());
+// setDefaultPreferences();
+/* mCalendar = new CalendarLocal();
+ mView = new CalendarView( mCalendar, this,"mCalendar " );
+ mView->hide();
+ //mView->resize(splash->size() );
+*/
+ initActions();
+
+#ifndef DESKTOP_VERSION
+//US iconToolBar->show();
+ qApp->processEvents();
+#endif
+ qDebug("Splashwidget x %d y %d w %d h %d", splash-> x(), splash->y(), splash->width(),splash-> height ());
+
+ int vh = height() ;
+ int vw = width();
+ qDebug("Toolbar hei %d ",iconToolBar->height() );
+/*US if ( iconToolBar->orientation () == Qt:: Horizontal ) {
+ vh -= iconToolBar->height();
+ } else {
+ vw -= iconToolBar->height();
+ }
+*/
+ //mView->setMaximumSize( splash->size() );
+ //mView->resize( splash->size() );
+ //qDebug("MainView x %d y %d w %d h %d", mView->x(),mView-> y(), mView->width(), mView->height ());
+/* mView->readSettings();
+ if( !QFile::exists( defaultFileName() ) ) {
+ mView->saveCalendar( defaultFileName() );
+ }
+ mView->openCalendar( defaultFileName() );
+ processIncidenceSelection( 0 );
+ connect( mView, SIGNAL( incidenceSelected( Incidence * ) ),
+ SLOT( processIncidenceSelection( Incidence * ) ) );
+ connect( mView, SIGNAL( modifiedChanged( bool ) ),
+ SLOT( slotModifiedChanged( bool ) ) );
+ connect( mView, SIGNAL( signalmodified() ),
+ SLOT( checkAlarms( ) ) );
+
+ connect( &mSaveTimer, SIGNAL( timeout() ), SLOT( save() ) );
+ connect( &alarmTimer, SIGNAL( timeout() ), SLOT( writeAlarm() ) );
+ mView->setModified( false );
+ mBlockAtStartup = false;
+ mView->setModified( false );
+ setCentralWidget( mView );
+ mView->show();
+*/
+ delete splash;
+
+ qApp->processEvents();
+//US qDebug("MainView x %d y %d w %d h %d", mView->x(),mView-> y(), mView->width(), mView->height ());
+
+}
+MainWindow::~MainWindow()
+{
+ qDebug("MainWindow::~MainWindow() ");
+ kdDebug() << "MainWindow()::~MainWindow()" << endl;
+ //save toolbar location
+/*
+ KOPrefs *p = KOPrefs::instance();
+ p->mToolBarHor = ( iconToolBar->orientation () == Qt:: Horizontal );
+ p->mToolBarUp = iconToolBar->x() > width()/2 ||
+ iconToolBar->y() > height()/2;
+ alarmTimer.stop();
+ mView->writeSettings();
+ writeAlarm();
+ if ( mCalendarModifiedFlag )
+ save();
+ delete mCalendar;
+*/
+}
+
+
+void MainWindow::closeEvent( QCloseEvent* ce )
+{
+
+ if ( ! KABPrefs::instance()->mAskForQuit ) {
+
+ ce->accept();
+ return;
+
+ }
+
+ switch( QMessageBox::information( this, "KA/Pi",
+ i18n("Do you really want\nto close KA/Pi?"),
+ i18n("Close!"), i18n("No"),
+ 0, 0 ) ) {
+ case 0:
+ ce->accept();
+ break;
+ case 1:
+ ce->ignore();
+ break;
+ case 2:
+
+ default:
+ break;
+ }
+
+
+}
+
+
+void MainWindow::recieve( const QCString& cmsg, const QByteArray& data )
+{
+/*
+ QDataStream stream( data, IO_ReadOnly );
+ // QMessageBox::about( this, "About KOrganizer/Pi", "*" +msg +"*" );
+
+
+ if ( cmsg == "-writeFile" ) {
+ mView->viewManager()->showWhatsNextView();
+ save();
+ setCaption( i18n("File written on AD request"));
+ showMaximized();
+ raise();
+#ifndef DESKTOP_VERSION
+ QCopEnvelope e3("kosaved", "blabla");
+#endif
+ return;
+
+ }
+ if ( cmsg == "-newCountdown" ) {
+ qDebug("newCountdown ");
+
+ }
+ QString msg ;;
+ QString allmsg = cmsg;
+ while ( allmsg.length() > 0 ) {
+ int nextC = allmsg.find( "-", 1 );
+ if ( nextC == -1 ) {
+ msg = allmsg;
+ allmsg = "";
+ } else{
+ msg = allmsg.left( nextC );
+ allmsg = allmsg.mid( nextC, allmsg.length()-nextC );
+ }
+ //qDebug("msg: %s all: %s ", msg.latin1(), allmsg.latin1() );
+ if ( msg == "-newEvent" ) {
+ mView->newEvent();
+ }
+ if ( msg == "-newTodo" ) {
+ mView->newTodo();
+
+ }
+ if ( msg == "-showWN" ) {
+ mView->viewManager()->showWhatsNextView();
+ }
+ if ( msg == "-showTodo" ) {
+ mView->viewManager()->showTodoView();
+ }
+ if ( msg == "-showList" ) {
+ mView->viewManager()->showListView();
+ }
+ else if ( msg == "-showDay" ) {
+ mView->viewManager()->showDayView();
+ }
+ else if ( msg == "-showWWeek" ) {
+ mView->viewManager()->showWorkWeekView();
+ }
+ else if ( msg == "-showWeek" ) {
+ mView->viewManager()->showWeekView();
+ }
+ else if ( msg == "-showTodo" ) {
+ mView->viewManager()->showTodoView();
+ }
+ else if ( msg == "-showJournal" ) {
+ mView->viewManager()->showJournalView();
+ }
+ else if ( msg == "-showKO" ) {
+ mView->viewManager()->showNextXView();
+ }
+ else if ( msg == "-showWNext" ) {
+ mView->viewManager()->showWhatsNextView();
+ }
+ }
+
+ showMaximized();
+ raise();
+*/
+}
+
+
+QPixmap MainWindow::loadPixmap( QString name )
+{
+ return KGlobal::iconLoader().loadPixmap( name );
+/*US use the advanced version of the iconloader
+#ifdef DESKTOP_VERSION
+ QPixmap pixmapLoader;
+ QString file;
+ file = QDir::homeDirPath()+"/kaddressbook/pics/" + name+".png";
+ //qDebug("pixmap name %s ", file.latin1());
+ pixmapLoader.load( file );
+ return pixmapLoader;
+#else
+ return Resource::loadPixmap( name );
+#endif
+*/
+}
+
+void MainWindow::initActions()
+{
+ iconToolBar->clear();
+ KABPrefs *p = KABPrefs::instance();
+ QPEMenuBar *menuBar1 = new QPEMenuBar( iconToolBar );
+ QPopupMenu *menuBar = new QPopupMenu( this );
+ menuBar1->insertItem( "ME", menuBar);
+ QPopupMenu *fileMenu = new QPopupMenu( this );
+ QPopupMenu *editMenu = new QPopupMenu( this );
+ QPopupMenu *viewMenu = new QPopupMenu( this );
+ QPopupMenu *settingsMenu = new QPopupMenu( this );
+ QPopupMenu *importMenu = new QPopupMenu( this );
+
+ menuBar1->setMaximumWidth( menuBar1->sizeHint().width() );
+
+ QIconSet icon;
+
+
+ icon = loadPixmap( pathString + "newtodo" );
+ configureToolBarMenu->insertItem(icon, "New todo", 20 );
+ QAction* nt_action = new QAction( "New Todo", icon, "New Todo...", 0, this );
+ nt_action->addTo( actionMenu );
+ connect( nt_action, SIGNAL( activated() ),
+ mView, SLOT( newTodo() ) );
+
+/*
+ QAction *action;
+ QIconSet icon;
+ // QPopupMenu *configureMenu= new QPopupMenu( menuBar );
+ configureToolBarMenu = new QPopupMenu( this );
+ configureToolBarMenu->setCheckable( true );
+#ifdef DESKTOP_VERSION
+ QString pathString = "";
+#else
+ QString pathString = "kaddressbook/";
+#endif
+ if ( QApplication::desktop()->width() < 480 )
+ pathString += "icons16/";
+ configureAgendaMenu = new QPopupMenu( menuBar );
+ configureAgendaMenu->setCheckable( true );
+ configureAgendaMenu->insertItem("Toggle Allday", 1 );
+ configureAgendaMenu->insertSeparator();
+ configureAgendaMenu->insertItem("Tiny", 4 );
+ configureAgendaMenu->insertItem("Small", 6 );
+ configureAgendaMenu->insertItem("Medium", 8 );
+ configureAgendaMenu->insertItem("Normal", 10 );
+ configureAgendaMenu->insertItem("Large", 12 );
+ configureAgendaMenu->insertItem("Big", 14 );
+ configureAgendaMenu->insertItem("Bigger", 16 );
+ configureAgendaMenu->insertItem("Biggest", 18 );
+ //configureMenu->insertItem( "AgendaSize",configureAgendaMenu );
+ icon = loadPixmap( pathString + "newevent" );
+ icon = loadPixmap( pathString + "newevent" );
+ configureToolBarMenu->insertItem("Stretched TB", 5 );
+ configureToolBarMenu->insertSeparator();
+ configureToolBarMenu->insertItem(icon, "New event", 10 );
+ QAction* ne_action = new QAction( "New Event", icon, "New Event...", 0, this );
+ ne_action->addTo( actionMenu );
+*/
+/*
+ connect( ne_action, SIGNAL( activated() ),
+ mView, SLOT( newEvent() ) );
+ icon = loadPixmap( pathString + "newtodo" );
+ configureToolBarMenu->insertItem(icon, "New todo", 20 );
+ QAction* nt_action = new QAction( "New Todo", icon, "New Todo...", 0, this );
+ nt_action->addTo( actionMenu );
+ connect( nt_action, SIGNAL( activated() ),
+ mView, SLOT( newTodo() ) );
+
+ action = new QAction( "Toggle FilterView", QPixmap(), "Toggle FilterView", 0, this );
+ action->addTo( viewMenu );
+ connect( action, SIGNAL( activated() ),
+ mView, SLOT( toggleFilter() ) );
+
+ viewMenu->insertSeparator();
+ icon = loadPixmap( pathString + "picker" );
+ action = new QAction( "Date Picker", icon, "Date Picker", 0, this );
+ action->addTo( viewMenu );
+ connect( action, SIGNAL( activated() ),
+ mView, SLOT( showDatePicker() ) );
+ action->addTo( iconToolBar );
+ viewMenu->insertSeparator();
+ icon = loadPixmap( pathString + "list" );
+ configureToolBarMenu->insertItem(icon, "Event list", 30 );
+ QAction* showlist_action = new QAction( "List", icon, "List", 0, this );
+ showlist_action->addTo( viewMenu );
+ connect( showlist_action, SIGNAL( activated() ),
+ mView->viewManager(), SLOT( showListView() ) );
+
+
+ icon = loadPixmap( pathString + "day" );
+ configureToolBarMenu->insertItem(icon, "One day", 40 );
+ QAction* day1_action = new QAction( "Day", icon, "Day", 0, this );
+ day1_action->addTo( viewMenu );
+ // action->addTo( toolBar );
+ connect( day1_action, SIGNAL( activated() ),
+ mView->viewManager(), SLOT( showDayView() ) );
+
+ icon = loadPixmap( pathString + "workweek" );
+ configureToolBarMenu->insertItem(icon, "Work week", 50 );
+ QAction* day5_action = new QAction( "Work Week", icon, "Work Week", 0, this );
+ day5_action->addTo( viewMenu );
+ connect( day5_action, SIGNAL( activated() ),
+ mView->viewManager(), SLOT( showWorkWeekView() ) );
+
+ icon = loadPixmap( pathString + "week" );
+ configureToolBarMenu->insertItem(icon, "Week", 60 );
+ QAction* day7_action = new QAction( "Week", icon, "Week", 0, this );
+ day7_action->addTo( viewMenu );
+ connect( day7_action, SIGNAL( activated() ),
+ mView->viewManager(), SLOT( showWeekView() ) );
+
+ icon = loadPixmap( pathString + "month" );
+ configureToolBarMenu->insertItem(icon, "Month", 70 );
+ QAction* month_action = new QAction( "Month", icon, "Month", 0, this );
+ month_action->addTo( viewMenu );
+ connect( month_action, SIGNAL( activated() ),
+ mView->viewManager(), SLOT( showMonthView() ) );
+
+ icon = loadPixmap( pathString + "todo" );
+ configureToolBarMenu->insertItem(icon, "Todo list", 80 );
+ QAction* todoview_action = new QAction( "Todo", icon, "Todo", 0, this );
+ todoview_action->addTo( viewMenu );
+ connect( todoview_action, SIGNAL( activated() ),
+ mView->viewManager(), SLOT( showTodoView() ) );
+
+ icon = loadPixmap( pathString + "journal" );
+ configureToolBarMenu->insertItem(icon, "Journal", 90 );
+ QAction* viewjournal_action = new QAction( "Journal", icon, "Journal", 0, this );
+ viewjournal_action->addTo( viewMenu );
+ connect( viewjournal_action, SIGNAL( activated() ),
+ mView->viewManager(), SLOT( showJournalView() ) );
+
+ icon = loadPixmap( pathString + "xdays" );
+ configureToolBarMenu->insertItem(icon, "Next days", 100,4 );
+ QAction* xdays_action = new QAction( "Next days", icon, "Next Days", 0, this );
+ xdays_action->addTo( viewMenu );
+ connect( xdays_action, SIGNAL( activated() ),
+ mView->viewManager(), SLOT( showNextXView() ) );
+
+ icon = loadPixmap( pathString + "whatsnext" );
+ configureToolBarMenu->insertItem(icon, "Whats next", 110, 4 );
+ QAction* whatsnext_action = new QAction( "What's Next", icon, "What's Next", 0, this );
+ whatsnext_action->addTo( viewMenu );
+ connect( whatsnext_action, SIGNAL( activated() ),
+ mView->viewManager(), SLOT( showWhatsNextView() ) );
+
+#if 0
+ action = new QAction( "view_timespan", "Time Span", 0, this );
+ action->addTo( viewMenu );
+ connect( action, SIGNAL( activated() ),
+ mView->viewManager(), SLOT( showTimeSpanView() ) );
+#endif
+
+ menuBar->insertItem( "View", viewMenu );
+
+
+#if 0
+ QPopupMenu *navigationMenu = new QPopupMenu( menuBar );
+
+ action = new QAction( "Go backward", "Go Backward", 0, navigationMenu );
+ action->addTo( navigationMenu );
+ connect( action, SIGNAL( activated() ),
+ mView, SLOT( goPrevious() ) );
+
+ action = new QAction( "Go forward", "Go Forward", 0, navigationMenu );
+ action->addTo( navigationMenu );
+ connect( action, SIGNAL( activated() ),
+ mView, SLOT( goNext() ) );
+
+ menuBar->insertItem( "Go", navigationMenu );
+#endif
+
+
+
+
+
+
+ mNewSubTodoAction = new QAction( "new_subtodo", "New Sub-Todo...", 0,
+ this );
+ mNewSubTodoAction->addTo( actionMenu );
+ connect( mNewSubTodoAction, SIGNAL( activated() ),
+ mView, SLOT( newSubTodo() ) );
+
+ actionMenu->insertSeparator();
+
+ mShowAction = new QAction( "show_incidence", "Show...", 0, this );
+ mShowAction->addTo( actionMenu );
+ connect( mShowAction, SIGNAL( activated() ),
+ mView, SLOT( showIncidence() ) );
+
+ mEditAction = new QAction( "edit_incidence", "Edit...", 0, this );
+ mEditAction->addTo( actionMenu );
+ connect( mEditAction, SIGNAL( activated() ),
+ mView, SLOT( editIncidence() ) );
+
+ mDeleteAction = new QAction( "delete_incidence", "Delete...", 0, this );
+ mDeleteAction->addTo( actionMenu );
+ connect( mDeleteAction, SIGNAL( activated() ),
+ mView, SLOT( deleteIncidence() ) );
+
+ actionMenu->insertSeparator();
+
+ action = new QAction( "purge_completed", i18n("Purge Completed"), 0,
+ this );
+ action->addTo( actionMenu );
+ connect( action, SIGNAL( activated() ), mView, SLOT( purgeCompleted() ) );
+
+ icon = loadPixmap( pathString + "search" );
+ QAction* search_action = new QAction( "search", icon, "Search...", 0, this );
+ configureToolBarMenu->insertItem(icon, "Search", 120 , 4);
+ search_action->addTo( actionMenu );
+ connect( search_action, SIGNAL( activated() ),
+ mView->dialogManager(), SLOT( showSearchDialog() ) );
+
+ icon = loadPixmap( pathString + "today" );
+ configureToolBarMenu->insertItem(icon, "Today", 130);
+ QAction* today_action = new QAction( "Today", icon, "Go to Today", 0, this );
+ today_action->addTo( actionMenu );
+ connect( today_action, SIGNAL( activated() ),
+ mView, SLOT( goToday() ) );
+
+ //#if 0
+ actionMenu->insertSeparator();
+
+ action = new QAction( "configure", "Configure...", 0, this );
+ action->addTo( actionMenu );
+ connect( action, SIGNAL( activated() ),
+ mView, SLOT( edit_options() ) );
+ //#endif
+
+ // actionMenu->insertSeparator();
+ action = new QAction( "import_qtopia", "Import (*.ics/*.vcs) file", 0,
+ this );
+ action->addTo( importMenu );
+ connect( action, SIGNAL( activated() ), SLOT( importIcal() ) );
+ action = new QAction( "import_quick", "Import last file", 0,
+ this );
+ action->addTo( importMenu );
+ connect( action, SIGNAL( activated() ), SLOT( quickImportIcal() ) );
+ importMenu->insertSeparator();
+ action = new QAction( "import_qtopia", "Import Opie/Qtopia Cal.", 0,
+ this );
+ action->addTo( importMenu );
+ importMenu->insertSeparator();
+ connect( action, SIGNAL( activated() ), SLOT( importQtopia() ) );
+
+ action = new QAction( "load_cal", "Load Calendar Backup", 0,
+ this );
+ action->addTo( importMenu );
+ connect( action, SIGNAL( activated() ), SLOT( loadCalendar() ) );
+
+ action = new QAction( "save_cal", "Save Calendar Backup", 0,
+ this );
+ action->addTo( importMenu );
+ connect( action, SIGNAL( activated() ), SLOT( saveCalendar() ) );
+
+ importMenu->insertSeparator();
+ action = new QAction( "import_qtopia", "Export VCalendar", 0,
+ this );
+ action->addTo( importMenu );
+ connect( action, SIGNAL( activated() ), SLOT( exportVCalendar() ) );
+
+
+ QPopupMenu *syncMenu = new QPopupMenu( this );
+ action = new QAction( "syncssh", "Remote via ssh/scp(not implemented)", 0,
+ this );
+ action->addTo( syncMenu );
+ connect( action, SIGNAL( activated() ), SLOT( syncSSH() ) );
+ action = new QAction( "synclocal", "With local file(not implemented)", 0,
+ this );
+ action->addTo( syncMenu );
+ connect( action, SIGNAL( activated() ), SLOT( syncLocalFile() ) );
+ action = new QAction( "quicksynclocal", "With last file(not implemented)", 0,
+ this );
+ action->addTo( syncMenu );
+ connect( action, SIGNAL( activated() ), SLOT( quickSyncLocalFile() ) );
+
+ menuBar->insertItem( "Actions", actionMenu );
+ menuBar->insertItem( "Load/Save", importMenu );
+ menuBar->insertItem( "Synchronize", syncMenu );
+ //menuBar->insertItem( "Configure",configureMenu );
+ //configureMenu->insertItem( "Toolbar",configureToolBarMenu );
+ menuBar->insertItem( "AgendaSize",configureAgendaMenu );
+ menuBar->insertItem( "Toolbar",configureToolBarMenu );
+ QPopupMenu *helpMenu = new QPopupMenu( menuBar );
+ icon = loadPixmap( "korganizer/korganizer" );
+ action = new QAction( "Key bindings", "Key Bindings...", 0, this );
+ action->addTo( helpMenu );
+ connect( action, SIGNAL( activated() ),
+ SLOT( keyBindings() ) );
+ action = new QAction( "Auto saving", "Auto saving...", 0, this );
+ action->addTo( helpMenu );
+ connect( action, SIGNAL( activated() ),
+ SLOT( aboutAutoSaving() ) );
+ action = new QAction( "Problemd", "Known Problems...", 0,this );
+ action->addTo( helpMenu );
+ connect( action, SIGNAL( activated() ),
+ SLOT( aboutKnownBugs() ) );
+ action = new QAction( "about", "About...", 0, this );
+ action->addTo( helpMenu );
+ connect( action, SIGNAL( activated() ),
+ SLOT( about() ) );
+ menuBar->insertItem( "Help", helpMenu );
+*/
+ //menuBar->insertSeparator();
+
+ // ******************************************************
+ // menubar icons
+
+
+ iconToolBar->setHorizontalStretchable (true );
+ //menuBar->insertItem( iconToolBar );
+ //xdays_action
+/*
+ if (p-> mShowIconNewEvent)
+ ne_action->addTo( iconToolBar );
+ if (p->mShowIconNewTodo )
+ nt_action->addTo( iconToolBar );
+ if (p-> mShowIconSearch)
+ search_action->addTo( iconToolBar );
+ if (p-> mShowIconNext)
+ whatsnext_action->addTo( iconToolBar );
+ if (p-> mShowIconNextDays)
+ xdays_action->addTo( iconToolBar );
+ if (p-> mShowIconList)
+ showlist_action->addTo( iconToolBar );
+ if (p-> mShowIconDay1)
+ day1_action->addTo( iconToolBar );
+ if (p-> mShowIconDay5)
+ day5_action->addTo( iconToolBar );
+ if (p-> mShowIconDay7)
+ day7_action->addTo( iconToolBar );
+ if (p-> mShowIconMonth)
+ month_action->addTo( iconToolBar );
+ if (p-> mShowIconTodoview)
+ todoview_action->addTo( iconToolBar );
+ if (p-> mShowIconJournal)
+ viewjournal_action->addTo( iconToolBar );
+ icon = loadPixmap( pathString + "2leftarrowB" );
+ configureToolBarMenu->insertItem(icon, "Prev. month", 200, 14);
+ if (p-> mShowIconBackFast) {
+ action = new QAction( "Prev month", icon, "Go Backward",0 , this );
+ connect( action, SIGNAL( activated() ),
+ mView, SLOT( goPreviousMonth() ) );
+ action->addTo( iconToolBar );
+ }
+ icon = loadPixmap( pathString + "1leftarrowB" );
+ configureToolBarMenu->insertItem(icon, "Go previous", 210,15);
+ if (p-> mShowIconBack) {
+ action = new QAction( "Go previous", icon, "Go Backward",0 , this );
+ connect( action, SIGNAL( activated() ),
+ mView, SLOT( goPrevious() ) );
+ action->addTo( iconToolBar );
+ }
+ if (p-> mShowIconToday)
+ today_action->addTo( iconToolBar );
+ icon = loadPixmap( pathString + "1rightarrowB" );
+ configureToolBarMenu->insertItem(icon, "Go next", 220);
+ if (p-> mShowIconForward) {
+ action = new QAction( "Go next", icon, "Go Backward",0 , this );
+ connect( action, SIGNAL( activated() ),
+ mView, SLOT( goNext() ) );
+ action->addTo( iconToolBar );
+ }
+ icon = loadPixmap( pathString + "2rightarrowB" );
+ configureToolBarMenu->insertItem(icon, "Next month", 230);
+ if (p-> mShowIconForwardFast) {
+ action = new QAction( "Next month", icon, "Go Backward",0 , this );
+ connect( action, SIGNAL( activated() ),
+ mView, SLOT( goNextMonth() ) );
+ action->addTo( iconToolBar );
+ }
+*/
+
+ configureToolBarMenu->insertItem("WhatsThis", 300);
+/*
+ if (p-> mShowIconNewEvent)
+ configureToolBarMenu->setItemChecked( 10, true );
+ if (p->mShowIconNewTodo )
+ configureToolBarMenu->setItemChecked( 20, true );
+ if (p-> mShowIconSearch)
+ configureToolBarMenu->setItemChecked( 120, true );
+ if (p-> mShowIconList)
+ configureToolBarMenu->setItemChecked( 30, true );
+ if (p-> mShowIconDay1)
+ configureToolBarMenu->setItemChecked( 40, true );
+ if (p-> mShowIconDay5)
+ configureToolBarMenu->setItemChecked( 50, true );
+ if (p-> mShowIconDay7)
+ configureToolBarMenu->setItemChecked( 60, true );
+ if (p-> mShowIconMonth)
+ configureToolBarMenu->setItemChecked( 70, true );
+ if (p-> mShowIconTodoview)
+ configureToolBarMenu->setItemChecked( 80, true );
+ if (p-> mShowIconBackFast)
+ configureToolBarMenu->setItemChecked( 200, true );
+ if (p-> mShowIconBack)
+ configureToolBarMenu->setItemChecked( 210, true );
+ if (p-> mShowIconToday)
+ configureToolBarMenu->setItemChecked( 130, true );
+ if (p-> mShowIconForward)
+ configureToolBarMenu->setItemChecked( 220, true );
+ if (p-> mShowIconForwardFast)
+ configureToolBarMenu->setItemChecked( 230, true );
+ if (p-> mShowIconNextDays)
+ configureToolBarMenu->setItemChecked( 100, true );
+ if (p-> mShowIconNext)
+ configureToolBarMenu->setItemChecked( 110, true );
+ if (p-> mShowIconJournal)
+ configureToolBarMenu->setItemChecked( 90, true );
+ if (p-> mShowIconWhatsThis)
+ configureToolBarMenu->setItemChecked( 300, true );
+
+ QLabel* dummy = new QLabel( iconToolBar );
+ dummy->setBackgroundColor( iconToolBar->backgroundColor() );
+ if (!p-> mShowIconStretch)
+ iconToolBar->setStretchableWidget ( dummy ) ;
+ else
+ configureToolBarMenu->setItemChecked( 5, true );
+ if (p-> mShowIconWhatsThis)
+ QWhatsThis::whatsThisButton ( iconToolBar );
+ connect( configureToolBarMenu, SIGNAL( activated( int ) ),this, SLOT(configureToolBar( int ) ) );
+ configureAgenda( p->mHourSize );
+ connect( configureAgendaMenu, SIGNAL( activated( int ) ),this, SLOT(configureAgenda( int ) ) );
+*/
+}
+/*
+void MainWindow::setDefaultPreferences()
+{
+ KOPrefs *p = KOPrefs::instance();
+
+ p->mCompactDialogs = true;
+ p->mConfirm = true;
+ p->mEnableQuickTodo = false;
+}
+*/
+void MainWindow::about()
+{
+ QMessageBox::about( this, "About KOrganizer/Pi",
+ "KOrganizer/Platform-independent\n"
+ "(KO/Pi) 1.6.0e - "
+#ifdef DESKTOP_VERSION
+ "Desktop Edition\n"
+#else
+ "PDA-Edition\n"
+ "for: Zaurus 5500 / 7x0 / 8x0\n"
+#endif
+ "(c) 2004 Lutz Rogowski\n"
+ "Email:lutz@pi-sync.net\n"
+ "KO/Pi is based on KOrganizer\n"
+ "(c) 2002,2003 Cornelius Schumacher\n"
+ "Email: schumacher@kde.org\n"
+ "KOrganizer/Pi is licensed\n"
+ "under the GPL.\n"
+ "KO/Pi can be compiled for\n"
+ "Linux, Zaurus-PDA and Windows\n"
+ "www.korganizer.org\n" );
+}
+/*
+void MainWindow::keyBindings()
+{
+ QMessageBox* msg;
+ msg = new QMessageBox( "Key bindings KOrganizer/Pi",
+ "Space: Toggle Fullscreen | P: Date Picker\n"
+ "H: This dialog | I: Show info | S: Search\n"
+ "F: Toggle Filterview | 1-4: Select Filter\n"
+ "N: Show next days | W: Whats next\n "
+ "V: Todo view | L: Event list view\n"
+ "T: Goto today | T+<ctrl>: New Todo\n"
+ "E: Edit item | E+<ctrl>: New Event\n"
+ "5: Work week view | 7: Week view\n"
+ "D: One day view | M: Month view\n"
+ "+,- : Zoom in/out Agenda | A: Toggle Allday\n"
+ "<ctrl>+<up>/<down>: Scroll todo view\n"
+ "<right>,C: Next week | <right>+<ctrl>: Next month\n"
+ "<left>,X: Prev. week | <left>+<ctrl>: Prev. month\n"
+ "<del>,<backspace>: Delete sel. item\n",
+ QMessageBox::NoIcon,
+ QMessageBox::Ok,
+ QMessageBox::NoButton,
+ QMessageBox::NoButton );
+ msg->exec();
+ delete msg;
+
+}
+void MainWindow::aboutAutoSaving()
+{
+ QMessageBox* msg;
+ msg = new QMessageBox( "Auto Saving in KOrganizer/Pi",
+ "After changing something, the data is\n"
+ "automatically saved to the file\n"
+ "~/Applications/korganizer/mycalendar.ics\n "
+ "after (configureable) one minute.\n"
+ "For safety reasons there is one autosaving\n"
+ "after 10 minutes (of idle time) again. The \n"
+ "data is saved automatically when closing KO/Pi\n"
+ "You can create a backup file \n"
+ "with: Load/Save - Save Calendar Backup\n",
+ QMessageBox::NoIcon,
+ QMessageBox::Ok,
+ QMessageBox::NoButton,
+ QMessageBox::NoButton);
+ msg->exec();
+ delete msg;
+
+
+}
+void MainWindow::aboutKnownBugs()
+{
+ QMessageBox* msg;
+ msg = new QMessageBox( "Known Problems in KOrganizer/Pi",
+ "1) The QWhatsThis help is not working.\n"
+ "There is only a black rectangle displayed\n"
+ "when clicking on an event.\n "
+ "2) Audio alarm is available!\n"
+ "as an additional small application\n"
+ "3) Syncing is missing.\n"
+ "Syncing via ssh/scp will be available in\n"
+ "KOrganizer/Pi 2.0\n"
+ "\n"
+ "Please report unexpected behaviour to\n"
+ "lutz@pi-sync.net\n",
+ QMessageBox::NoIcon,
+ QMessageBox::Ok,
+ QMessageBox::NoButton,
+ QMessageBox::NoButton);
+ msg->exec();
+ delete msg;
+
+}
+
+QString MainWindow::defaultFileName()
+{
+#ifndef DESKTOP_VERSION
+ return Global::applicationFileName( "korganizer", "mycalendar.ics" );
+#else
+ // pending
+ QString file;
+ file = QDir::homeDirPath()+"/korganizer/mycalendar.ics";
+ return QDir::convertSeparators( file );
+#endif
+}
+
+void MainWindow::processIncidenceSelection( Incidence *incidence )
+{
+ if ( !incidence ) {
+ enableIncidenceActions( false );
+
+ mNewSubTodoAction->setEnabled( false );
+ setCaptionToDates();
+ return;
+
+ }
+
+ QString startString = "";
+ if ( incidence->type() != "Todo" ) {
+ if ( incidence->dtStart().date() < incidence->dtEnd().date() ) {
+ startString = ": "+incidence->dtStart().time().toString().left(5);
+ startString += " "+ incidence->dtStart().date().toString();
+ startString += "-"+incidence->dtEnd().time().toString().left(5);
+ startString += " "+ incidence->dtEnd().date().toString();
+
+ } else {
+ if ( incidence->dtStart().time() != incidence->dtEnd().time() )
+ startString = ": "+incidence->dtStart().time().toString().left(5)+"-"+incidence->dtEnd().time().toString().left(5);
+ startString +=" "+incidence->dtStart().date().toString();
+ }
+
+ }
+ else
+ startString = ": (Prio "+QString::number( (( KCal::Todo*)incidence)->priority() ) +") "+QString::number( (( KCal::Todo*)incidence)->percentComplete() ) +"\% completed";
+
+ setCaption( incidence->summary()+startString);
+
+ enableIncidenceActions( true );
+
+ if ( incidence->type() == "Event" ) {
+ mShowAction->setText( i18n("Show Event...") );
+ mEditAction->setText( i18n("Edit Event...") );
+ mDeleteAction->setText( i18n("Delete Event...") );
+
+ mNewSubTodoAction->setEnabled( false );
+ } else if ( incidence->type() == "Todo" ) {
+ mShowAction->setText( i18n("Show Todo...") );
+ mEditAction->setText( i18n("Edit Todo...") );
+ mDeleteAction->setText( i18n("Delete Todo...") );
+
+ mNewSubTodoAction->setEnabled( true );
+ } else {
+ mShowAction->setText( i18n("Show...") );
+ mShowAction->setText( i18n("Edit...") );
+ mShowAction->setText( i18n("Delete...") );
+
+ mNewSubTodoAction->setEnabled( false );
+ }
+}
+
+void MainWindow::enableIncidenceActions( bool enabled )
+{
+ mShowAction->setEnabled( enabled );
+ mEditAction->setEnabled( enabled );
+ mDeleteAction->setEnabled( enabled );
+}
+
+void MainWindow::importQtopia()
+{
+#ifndef DESKTOP_VERSION
+ int result = QMessageBox::warning( this, "KO/Pi: Warning!",
+ "When importing a calendar twice\n"
+ "duplicated events will be ignored!\n"
+ "You can create a backup file with\n"
+ "Load/Save - Save Calendar Backup\n"
+ "to revert importing",
+ "Import!", "Cancel", 0,
+ 0, 1 );
+ if ( result == 0 ) {
+ QString datebook = Global::applicationFileName( "datebook", "datebook.xml");
+ QString todolist = Global::applicationFileName( "todolist", "todolist.xml");
+ QString categories = QString( getenv( "HOME" ) ) + "/Settings/Categories.xml";
+ mView->importQtopia( categories, datebook, todolist );
+ }
+#else
+ int result = QMessageBox::warning( this, "KO/Pi: Warning!",
+ "NOT SUPPORTED \n"
+ "ON DESKTOP!\n",
+ "OK", "Cancel", 0,
+ 0, 1 );
+
+#endif
+}
+void MainWindow::checkAlarms()
+{
+ if ( mBlockAtStartup )
+ return;
+ alarmTimer.start( 1000 * 3);
+
+}
+void MainWindow::slotModifiedChanged( bool changed )
+{
+ if ( mBlockAtStartup )
+ return;
+ int msec;
+ // we store the changes after 1 minute,
+ // and for safety reasons after 10 minutes again
+ if ( !mBlockSaveFlag )
+ msec = (1000 * 60*KOPrefs::instance()->mAutoSaveInterval) +1000;
+ else
+ msec = 1000 * 600;
+ mSaveTimer.start( msec, true ); // 1 minute
+ qDebug("KO: Saving File in %d secs!", msec/1000);
+ mCalendarModifiedFlag = true;
+}
+void MainWindow::writeAlarm()
+{
+ if ( mBlockAtStartup )
+ return;
+ //QCopEnvelope e3("koalarm", "-showWN");
+ QDateTime nextA ;
+ QDateTime reference ( QDate( 2000, 1, 1 ) );
+ QString summary;
+ alarmTimer.stop();
+ Calendar* cal = mView->calendar();
+ if ( ! cal ){
+ qDebug("KO: Calendar undefined. No alarm notification");
+ return;
+ }
+ nextA = cal->nextAlarm( 720 );
+ summary = cal->nextSummary();
+ qDebug("KO: Next Alarm %s %s", nextA.toString().latin1(), summary.latin1());
+ if ( nextA < QDateTime::currentDateTime().addDays( 720-1 ) ) {
+ KConfig *config = KOGlobals::config();
+ config->setGroup("NextSystemAlarm");
+ QString date, sum;
+ date = config->readEntry("TimeDateinSecs", "xxx");
+ bool ok = false;
+ int shsecs = date.toInt(&ok );
+ QDateTime scheduledAlarm;
+ QDateTime eventDateTime = cal->nextAlarmEvent();
+ sum = config->readEntry("Summary", "sss");
+ if ( ok ) {
+ scheduledAlarm = reference.addSecs( shsecs );
+ //qDebug("sheduledAlarm %s ", scheduledAlarm.toString().latin1());
+ if ( scheduledAlarm == nextA && sum == summary ) {
+ qDebug("KO: Same alarm time+summary - nothing to do! ");
+ return;
+ }
+ }
+ if ( ok ) {
+ // delete alarm from system
+ //qDebug("delete Alarm %s ", scheduledAlarm.toString().latin1());
+#ifndef DESKTOP_VERSION
+ AlarmServer::deleteAlarm ( scheduledAlarm,"koalarm" , sum.latin1() );
+#endif
+ }
+ // add new alarm to system
+ qDebug("KO: Add Alarm: %s ", nextA.toString().latin1() );
+#ifndef DESKTOP_VERSION
+ AlarmServer::addAlarm ( nextA,"koalarm", summary.latin1() );
+#endif
+ // write new alarm to config file
+ //qDebug("Entry %s %s ", date.latin1(), sum.latin1());
+ int secs = reference.secsTo( nextA );
+ //qDebug(" secs %d ", secs);
+ setCaption( i18n("Next Alarm: ")+ nextA.toString() +"-"+summary );
+ config->writeEntry("TimeDateinSecs",QString::number ( secs ));
+ config->writeEntry("Summary",summary);
+ config->writeEntry("TimeDate",nextA.toString());
+ config->writeEntry("WriteDateTime",QDateTime::currentDateTime().toString());
+ config->writeEntry("EventStartDateTime",eventDateTime.toString());
+ config->writeEntry("SystemNotifyInSecs",QString::number (QDateTime::currentDateTime().secsTo( nextA ) ));
+ config->sync();
+
+ }
+}
+void MainWindow::save()
+{
+ if ( mBlockSaveFlag )
+ return;
+
+ mBlockSaveFlag = true;
+ QTime neededSaveTime = QDateTime::currentDateTime().time();
+ setCaption("KO/Pi:Saving Data to File ..." );
+ qDebug("KO: Start saving data to file!");
+ mView->saveCalendar( defaultFileName() );
+ int msNeeded = neededSaveTime.msecsTo( QDateTime::currentDateTime().time() );
+ qDebug("KO: Needed %d ms for saving.",msNeeded );
+ QString savemes;
+ savemes.sprintf("KO/Pi:File Saved. Needed %d sec, %d ms",(msNeeded/1000)%100,msNeeded%1000 );
+ setCaption(savemes);
+ mCalendarModifiedFlag = false;
+ mBlockSaveFlag = false;
+}
+
+void MainWindow::keyReleaseEvent ( QKeyEvent * e)
+{
+ if ( !e->isAutoRepeat() ) {
+ mFlagKeyPressed = false;
+ }
+}
+void MainWindow::keyPressEvent ( QKeyEvent * e )
+{
+ qApp->processEvents();
+ if ( e->isAutoRepeat() && !mFlagKeyPressed ) {
+ e->ignore();
+ // qDebug(" ignore %d",e->isAutoRepeat() );
+ return;
+ }
+ if (! e->isAutoRepeat() )
+ mFlagKeyPressed = true;
+ KOPrefs *p = KOPrefs::instance();
+ bool showSelectedDates = false;
+ int size;
+ //qDebug("MainWindow::keyPressEvent ");
+ switch ( e->key() ) {
+ case Qt::Key_Right:
+ if ( e->state() == Qt::ControlButton )
+ mView->goNextMonth();
+ else
+ mView->goNext();
+ showSelectedDates = true;
+ break;
+ case Qt::Key_Left:
+ if ( e->state() == Qt::ControlButton )
+ mView->goPreviousMonth();
+ else
+ mView->goPrevious();
+ showSelectedDates = true;
+ break;
+ case Qt::Key_Down:
+ mView->viewManager()->agendaView()->scrollOneHourDown();
+ break;
+ case Qt::Key_Up:
+ mView->viewManager()->agendaView()->scrollOneHourUp();
+ break;
+ case Qt::Key_I:
+ mView->showIncidence();
+ break;
+ case Qt::Key_Delete:
+ case Qt::Key_Backspace:
+ mView->deleteIncidence();
+ break;
+ case Qt::Key_D:
+ mView->viewManager()->showDayView();
+ showSelectedDates = true;
+ break;
+ case Qt::Key_0:
+ mView->toggleFilerEnabled( );
+ break;
+ case Qt::Key_1:
+ mView->selectFilter( 0 );
+ break;
+ case Qt::Key_2:
+ mView->selectFilter( 1 );
+ break;
+ case Qt::Key_3:
+ mView->selectFilter( 2 );
+ break;
+ case Qt::Key_4:
+ mView->selectFilter( 3 );
+ break;
+ case Qt::Key_5:
+ mView->viewManager()->showWorkWeekView();
+ showSelectedDates = true;
+ break;
+ case Qt::Key_7:
+ mView->viewManager()->showWeekView();
+ showSelectedDates = true;
+ break;
+ case Qt::Key_M:
+ mView->viewManager()->showMonthView();
+ showSelectedDates = true;
+ break;
+ case Qt::Key_Insert:
+ mView->newEvent();
+ break;
+ case Qt::Key_S :
+ mView->dialogManager()->showSearchDialog();
+ break;
+ case Qt::Key_H :
+ keyBindings();
+ break;
+ case Qt::Key_W:
+ mView->viewManager()->showWhatsNextView();
+ break;
+ case Qt::Key_L:
+ mView->viewManager()->showListView();
+ break;
+ case Qt::Key_N:
+ mView->viewManager()->showNextXView();
+ showSelectedDates = true;
+ break;
+ case Qt::Key_V:
+ mView->viewManager()->showTodoView();
+ break;
+ case Qt::Key_C:
+ mView->goNext();
+ showSelectedDates = true;
+ break;
+ case Qt::Key_P:
+ mView->showDatePicker( );
+ break;
+ case Qt::Key_F:
+ mView->toggleFilter();
+ break;
+ case Qt::Key_X:
+ mView->goPrevious();
+ showSelectedDates = true;
+ break;
+ case Qt::Key_Space:
+ mView->toggleExpand();
+ break;
+ case Qt::Key_A:
+ mView->toggleAllDaySize();
+ break;
+ case Qt::Key_T:
+ if ( e->state() == Qt::ControlButton )
+ mView->newTodo();
+ else {
+ mView->goToday();
+ showSelectedDates = true;
+ }
+ break;
+ case Qt::Key_J:
+ mView->viewManager()->showJournalView();
+ break;
+ case Qt::Key_Return:
+ case Qt::Key_E:
+ if ( e->state() == Qt::ControlButton )
+ mView->newEvent();
+ else
+ mView->editIncidence();
+ break;
+ case Qt::Key_Plus:
+ size = p->mHourSize +2;
+ if ( size <= 18 )
+ configureAgenda( size );
+ break;
+ case Qt::Key_Minus:
+ size = p->mHourSize - 2;
+ if ( size >= 4 )
+ configureAgenda( size );
+ break;
+
+
+ default:
+ e->ignore();
+ }
+
+ if ( showSelectedDates ) {
+ ;// setCaptionToDates();
+ }
+
+}
+
+void MainWindow::configureToolBar( int item )
+{
+
+ configureToolBarMenu->setItemChecked( item, !configureToolBarMenu-> isItemChecked ( item ) );
+ KOPrefs *p = KOPrefs::instance();
+ p-> mShowIconStretch= configureToolBarMenu->isItemChecked( 5 );
+ p-> mShowIconNewEvent= configureToolBarMenu->isItemChecked( 10 );
+ p->mShowIconNewTodo = configureToolBarMenu->isItemChecked( 20 );
+ p-> mShowIconSearch= configureToolBarMenu->isItemChecked( 120 );
+ p-> mShowIconList= configureToolBarMenu->isItemChecked( 30 );
+ p-> mShowIconDay1= configureToolBarMenu->isItemChecked( 40 );
+ p-> mShowIconDay5= configureToolBarMenu->isItemChecked( 50 );
+ p-> mShowIconDay7= configureToolBarMenu->isItemChecked( 60 );
+ p-> mShowIconMonth= configureToolBarMenu->isItemChecked( 70 );
+ p-> mShowIconTodoview= configureToolBarMenu->isItemChecked( 80 );
+ p-> mShowIconBackFast= configureToolBarMenu->isItemChecked( 200 );
+ p-> mShowIconBack = configureToolBarMenu->isItemChecked( 210 );
+ p-> mShowIconToday= configureToolBarMenu->isItemChecked( 130 );
+ p-> mShowIconForward= configureToolBarMenu->isItemChecked( 220 );
+ p-> mShowIconForwardFast= configureToolBarMenu->isItemChecked( 230 );
+ p-> mShowIconNextDays= configureToolBarMenu->isItemChecked( 100 );
+ p-> mShowIconNext= configureToolBarMenu->isItemChecked( 110 );
+ p-> mShowIconJournal= configureToolBarMenu->isItemChecked( 90 );
+ p-> mShowIconWhatsThis= configureToolBarMenu->isItemChecked( 300 );
+ initActions();
+}
+
+void MainWindow::setCaptionToDates()
+{
+ QString selDates;
+ selDates = mView->startDate().toString();
+ if (mView->startDate() < mView->endDate() )
+ selDates += " - " + mView->endDate().toString();
+ setCaption( "Dates: " + selDates );
+
+}
+// parameter item == 0: reinit
+void MainWindow::configureAgenda( int item )
+{
+
+ KOPrefs *p = KOPrefs::instance();
+
+ int i;
+ if ( item == 1 ) {
+ mView->toggleAllDaySize();
+ return;
+ }
+ // do not allow 4 for widgets higher than 480
+ if ( QApplication::desktop()->height() > 480 ) {
+ if ( item == 4 )
+ item = 6;
+ }
+ for ( i = 4; i <= 18; i= i+2 )
+ configureAgendaMenu->setItemChecked( i, false );
+ configureAgendaMenu->setItemChecked( item, true );
+ if ( p->mHourSize == item )
+ return;
+ p->mHourSize=item;
+ mView->viewManager()->agendaView()->updateConfig();
+}
+
+void MainWindow::saveCalendar()
+{
+ QString fn = KOPrefs::instance()->mLastSaveFile;
+ fn = KFileDialog::getSaveFileName( fn, "Save backup filename", this );
+
+ if ( fn == "" )
+ return;
+ QFileInfo info;
+ info.setFile( fn );
+ QString mes;
+ bool createbup = true;
+ if ( info. exists() ) {
+ mes.sprintf( "Backup file\nalready exists!\nOld backup file from:\n%s\nOverwrite?\n",info.lastModified ().toString().latin1() );
+ int result = QMessageBox::warning( this, "KO/Pi: Warning!",mes,
+ "Overwrite!", "Cancel", 0,
+ 0, 1 );
+ if ( result != 0 ) {
+ createbup = false;
+ }
+ }
+ if ( createbup ) {
+ mView->saveCalendar( fn );
+ mes.sprintf("KO/Pi:Saved %s",fn.latin1() );
+ KOPrefs::instance()->mLastSaveFile = fn;
+ setCaption(mes);
+ }
+}
+void MainWindow::loadCalendar()
+{
+
+ QString fn = KOPrefs::instance()->mLastLoadFile;
+ fn = KFileDialog::getOpenFileName( fn, "Load backup filename", this );
+
+ if ( fn == "" )
+ return;
+ QFileInfo info;
+ info.setFile( fn );
+ QString mess;
+ bool loadbup = true;
+ if ( info. exists() ) {
+ mess.sprintf( "Backup file from:\n%s\nLoading backup\nfile will delete\nyour current Data!\n",info.lastModified ().toString().latin1() );
+ int result = QMessageBox::warning( this, "KO/Pi: Warning!",
+ mess,
+ "Load!", "Cancel", 0,
+ 0, 1 );
+ if ( result != 0 ) {
+ loadbup = false;
+ }
+ } else {
+ QMessageBox::warning( this, "KO/Pi: Warning!",
+ "Backup file\ndoes not exist!\n"
+ "Nothing loaded!", 0, 0,
+ 0, 1 );
+
+ return;
+ }
+ if ( loadbup ) {
+ mView->openCalendar( fn );
+ KOPrefs::instance()->mLastLoadFile = fn;
+ mess.sprintf("KO/Pi:Loaded %s",fn.latin1() );
+ setCaption(mess);
+ }
+
+}
+void MainWindow::quickImportIcal()
+{
+ importFile( KOPrefs::instance()->mLastImportFile, false );
+}
+void MainWindow::importFile( QString fn, bool quick )
+{
+ QFileInfo info;
+ info.setFile( fn );
+ QString mess;
+ bool loadbup = true;
+ if ( !info. exists() ) {
+ mess= "Import file \n..."+fn.right( 30)+ "\ndoes not exist!\nNothing imported!\n";
+ int result = QMessageBox::warning( this, "KO/Pi: Warning!",
+ mess );
+ return;
+ }
+ int result = 0;
+ if ( !quick ) {
+ mess.sprintf( "Import file \n..."+fn.right( 25)+"\nfrom:\n%s\nDuplicated entries\nwill not be imported!\n",info.lastModified ().toString().latin1() );
+ result = QMessageBox::warning( this, "KO/Pi: Warning!",
+ mess,
+ "Import", "Cancel", 0,
+ 0, 1 );
+ }
+ if ( result == 0 ) {
+ if ( mView->openCalendar( fn, true )) {
+ KOPrefs::instance()->mLastImportFile = fn;
+ setCaption(i18n(" "));
+ setCaption(i18n("Imported file successfully"));
+ } else {
+ setCaption(i18n("Error importing file"));
+ }
+ }
+}
+void MainWindow::importIcal()
+{
+
+ QString fn =KOPrefs::instance()->mLastImportFile;
+
+ fn =KFileDialog:: getOpenFileName( fn, "Import filename(*.ics/*.vcs)", this );
+ if ( fn == "" )
+ return;
+ importFile( fn, true );
+
+}
+
+void MainWindow::exportVCalendar()
+{
+ QString fn = KOPrefs::instance()->mLastVcalFile;
+ fn = KFileDialog::getSaveFileName( fn, "Export vcal filename(*.vcs)", this );
+ if ( fn == "" )
+ return;
+ QFileInfo info;
+ info.setFile( fn );
+ QString mes;
+ bool createbup = true;
+ if ( info. exists() ) {
+ mes.sprintf( i18n("Save file\nalready exists!\nOld save file from:\n%s\nOverwrite?\n"),info.lastModified ().toString().latin1() );
+ int result = QMessageBox::warning( this, "KO/Pi: Warning!",mes,
+ "Overwrite!", "Cancel", 0,
+ 0, 1 );
+ if ( result != 0 ) {
+ createbup = false;
+ }
+ }
+ if ( createbup ) {
+ if ( mView->exportVCalendar( fn ) ) {
+ KOPrefs::instance()->mLastVcalFile = fn;
+ if ( fn.length() > 20 )
+ mes.sprintf(i18n("KO/Pi:Exported to ...%s"),(fn.right(20)).latin1() );
+ else
+ mes.sprintf(i18n("KO/Pi:Exported to %s"),fn.latin1() );
+ setCaption(mes);
+ }
+ }
+
+}
+
+QString MainWindow::getPassword( )
+{
+ QString retfile = "";
+ QDialog dia ( this, "input-dialog", true );
+ QLineEdit lab ( &dia );
+ lab.setEchoMode( QLineEdit::Password );
+ QVBoxLayout lay( &dia );
+ lay.setMargin(7);
+ lay.setSpacing(7);
+ lay.addWidget( &lab);
+ dia.setFixedSize( 230,50 );
+ dia.setCaption( i18n("Input password") );
+ dia.show();
+ int res = dia.exec();
+ if ( res )
+ retfile = lab.text();
+ return retfile;
+
+}
+#ifndef _WIN32_
+#include <unistd.h>
+#endif
+void MainWindow::syncLocalFile()
+{
+
+ QString fn =KOPrefs::instance()->mLastSyncedLocalFile;
+
+ fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this );
+ if ( fn == "" )
+ return;
+ syncWithFile( fn, false );
+
+}
+
+void MainWindow::syncWithFile( QString fn , bool quick )
+{
+ QFileInfo info;
+ info.setFile( fn );
+ QString mess;
+ bool loadbup = true;
+ if ( !info. exists() ) {
+ mess.sprintf( i18n( "Sync file \n...%s\ndoes not exist!\nNothing synced!\n"),fn.right( 30).latin1() );
+ int result = QMessageBox::warning( this, "KO/Pi: Warning!",
+ mess );
+ return;
+ }
+ int result = 0;
+ if ( !quick ) {
+ mess.sprintf( "Sync with file \n..."+fn.right( 25)+"\nfrom:\n%s\n",info.lastModified ().toString().latin1() );
+ result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
+ mess,
+ i18n("Sync"), i18n("Cancel"), 0,
+ 0, 1 );
+ }
+ if ( KOPrefs::instance()->mAskForPreferences )
+ mView->edit_sync_options();
+ if ( result == 0 ) {
+ qDebug("Now sycing ... ");
+ mView->syncCalendar( fn, true );
+ if ( ! quick )
+ KOPrefs::instance()->mLastSyncedLocalFile = fn;
+ }
+
+}
+
+void MainWindow::quickSyncLocalFile()
+{
+ qDebug("quickSyncLocalFile() ");
+ syncWithFile( KOPrefs::instance()->mLastSyncedLocalFile, false );
+}
+
+void MainWindow::syncSSH()
+{
+ QTime timer;
+ timer.start();
+ qDebug("MainWindow::syncssh() ");
+ KOPrefs *p = KOPrefs::instance();
+ QString localFile = p->mLocalTempFile;
+ QString remoteIP = p->mRemoteIP;
+ QString remoteUser = p->mRemoteUser;
+ QString remoteFile = p->mRemoteFile;
+ if ( p->mUsePassWd && p->mRemotePassWd.length() > 0 )
+ remoteUser += ":" + p->mRemotePassWd;
+
+ QString question = i18n("Do you really want\nto remote sync?\n \n") +
+ i18n("IP: " ) +remoteIP +"\n" +
+ i18n("User: " ) + remoteUser +"\n" ;
+ int maxlen = 30;
+ if ( QApplication::desktop()->width() > 320 )
+ maxlen += 25;
+ if ( remoteFile.length() > maxlen )
+ question += i18n("Remote file:\n..." ) + remoteFile.right(maxlen) +"\n";
+ else
+ question += i18n("Remote file:\n " ) + remoteFile +"\n";
+ if ( localFile.length() > maxlen )
+ question += i18n("Local temp file:\n..." ) + localFile.right(maxlen) +"\n";
+ else
+ question += i18n("Local temp file:\n " ) + localFile +"\n";
+
+ if ( QMessageBox::information( this, "KO/Pi Sync",
+ question,
+ i18n("Yes"), i18n("No"),
+ 0, 0 ) != 0 )
+ return;
+ if ( !p->mUsePassWd ) {
+ QString pass = getPassword();
+ if ( pass.length() > 0 )
+ remoteUser += ":" + pass;
+ }
+ QString command = "scp " + remoteUser + "@" + remoteIP +":" + remoteFile +" " +localFile;
+ setCaption ( i18n( "Copy remote file to local machine..." ) );
+ int fileSize = 0;
+ int result = system ( command );
+ // 0 : okay
+ // 256: no such file or dir
+ //
+ qDebug("KO: Remote copy result(0 = okay): %d ",result );
+ if ( result != 0 ) {
+ int len = maxlen;
+ while ( len < command.length() ) {
+ command.insert( len , "\n" );
+ len += maxlen +2;
+ }
+ question = i18n("Sorry, the copy command failed!\nCommand was:\n") + command + "\n \nTry command on console to get more\ndetailed info about the reason.\n";
+ QMessageBox::information( this, "KO/Pi Sync - ERROR",
+ question,
+ i18n("Okay!")) ;
+ return;
+ }
+
+
+ setCaption ( i18n( "Copying succeed. Syncing not yet implemented" ) );
+ syncWithFile(localFile , true );
+ return;
+#if 0
+ system ("scp zaurus@192.168.0.65:/home/zaurus/Applications/korganizer/mycalendar.ics /home/polo/Applications/korganizer/z_sync.ics");
+ while ( timer.elapsed() < 5000 )
+ qApp->processEvents();
+
+ qDebug("MainWindow::merging) ");
+ mView->syncCalendar( "/home/polo/Applications/korganizer/z_sync.ics", 0 );
+ while ( mBlockSaveFlag )
+ qApp->processEvents();
+ save();
+ system ("scp /home/polo/Applications/korganizer/mycalendar.ics zaurus@192.168.0.65:/home/zaurus/Applications/korganizer/mycalendar.ics");
+#endif
+
+}
+*/
+
diff --git a/kaddressbook/old_mainwindow.h b/kaddressbook/old_mainwindow.h
new file mode 100644
index 0000000..7b6f68c
--- a/dev/null
+++ b/kaddressbook/old_mainwindow.h
@@ -0,0 +1,122 @@
+#ifndef KADR_MAINWINDOW_H
+#define KADR_MAINWINDOW_H
+
+#include <qmainwindow.h>
+#include "kabcore.h"
+
+//US#include <qtimer.h>
+
+//US#include <libkcal/incidence.h>
+
+//US#include "simplealarmclient.h"
+
+//USclass QAction;
+//USclass CalendarView;
+
+//US#ifdef DESKTOP_VERSION
+//US#define QPEToolBar QToolBar
+//US#define QPEMenuBar QMenuBar
+//US#endif
+
+class KABCore;
+
+//USclass QPEToolBar;
+
+//US namespace KACore {
+//USclass CalendarLocal;
+//US}
+
+//USusing namespace KACore;
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+ public:
+ MainWindow( QWidget *parent = 0, const char *name = 0, QString command = "");
+ ~MainWindow();
+
+ public slots:
+// void configureAgenda( int );
+ void recieve( const QCString& msg, const QByteArray& data );
+
+ protected slots:
+/*
+ void setCaptionToDates();
+
+ void about();
+
+ void keyBindings();
+ void aboutAutoSaving();;
+ void aboutKnownBugs();
+
+ void processIncidenceSelection( Incidence * );
+
+ void importQtopia();
+ void importIcal();
+ void importFile( QString, bool );
+ void quickImportIcal();
+
+ void slotModifiedChanged( bool );
+
+ void save();
+ void configureToolBar( int );
+ void saveCalendar();
+ void loadCalendar();
+ void exportVCalendar();
+ void checkAlarms();
+ void writeAlarm();
+
+
+ void syncSSH();
+ void syncLocalFile();
+ void syncWithFile( QString, bool );
+ void quickSyncLocalFile();
+
+
+ protected:
+ QString defaultFileName();
+
+ void enableIncidenceActions( bool );
+*/
+
+ private:
+/*
+ bool mFlagKeyPressed;
+ bool mBlockAtStartup;
+
+ QPEToolBar *iconToolBar;
+
+ void initActions();
+*/
+/* void setDefaultPreferences();
+ void keyPressEvent ( QKeyEvent * ) ;
+ void keyReleaseEvent ( QKeyEvent * ) ;
+
+ QPopupMenu *configureToolBarMenu;
+ QPopupMenu *configureAgendaMenu;
+ CalendarLocal *mCalendar;
+ CalendarView *mView;
+ QString getPassword();
+ QAction *mNewSubTodoAction;
+
+ QAction *mShowAction;
+ QAction *mEditAction;
+ QAction *mDeleteAction;
+
+ void closeEvent( QCloseEvent* ce );
+
+ SimpleAlarmClient mAlarmClient;
+
+ QTimer mSaveTimer;
+ QTimer alarmTimer;
+ bool mBlockSaveFlag;
+ bool mCalendarModifiedFlag;
+
+ QPixmap loadPixmap( QString );
+*/
+ private:
+ KABCore *mCore;
+
+};
+
+#endif
diff --git a/kaddressbook/phoneeditwidget.cpp b/kaddressbook/phoneeditwidget.cpp
new file mode 100644
index 0000000..78b9941
--- a/dev/null
+++ b/kaddressbook/phoneeditwidget.cpp
@@ -0,0 +1,532 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include <qlayout.h>
+#include <qlabel.h>
+#include <qtooltip.h>
+#include <qpushbutton.h>
+#include <qcheckbox.h>
+#include <qstring.h>
+#include <qlistbox.h>
+#include <qlistview.h>
+#include <qbuttongroup.h>
+
+#include <kbuttonbox.h>
+#include <klistview.h>
+#include <kapplication.h>
+#include <qapplication.h>
+#include <kconfig.h>
+#include <klineedit.h>
+#include <kcombobox.h>
+#include <klocale.h>
+#include <kdebug.h>
+#include <kglobal.h>
+#include <kiconloader.h>
+
+#include <kabc/phonenumber.h>
+
+#include "typecombo.h"
+
+#include "phoneeditwidget.h"
+
+PhoneEditWidget::PhoneEditWidget( QWidget *parent, const char *name )
+ : QWidget( parent, name )
+{
+ QGridLayout *layout = new QGridLayout( this, 4, 1 );
+//US layout->setSpacing( KDialog::spacingHint() );
+ layout->setSpacing( KDialogBase::spacingHintSmall() );
+
+
+
+ QLabel* label = new QLabel( this );
+//US loadIcon call is ambiguous. Add one more parameter
+//US label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop ) );
+ label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop, 0 ) );
+ label->setAlignment( AlignCenter );
+//US layout->addMultiCellWidget( label, 0, 1, 3, 3 );
+ layout->addWidget( label, 0, 0 );
+
+ QPushButton *editButton = new QPushButton( i18n( "Edit Phone Numbers..." ),
+ this );
+ if ( QApplication::desktop()->width() < 640 )
+ layout->addWidget( editButton, 0, 1 );
+ else
+ layout->addMultiCellWidget( editButton, 0, 0, 1, 3);
+
+ mPrefCombo = new PhoneTypeCombo( mPhoneList, this );
+ mPrefEdit = new KLineEdit( this );
+ //mPrefEdit->setMinimumWidth( int(mPrefEdit->sizeHint().width() * 1.5) );
+ mPrefCombo->setLineEdit( mPrefEdit );
+ layout->addWidget( mPrefCombo, 1, 0 );
+ layout->addWidget( mPrefEdit, 1, 1 );
+ int x = 1, y = 2;
+ if ( QApplication::desktop()->width() < 640 ) {
+ ++x;
+ y = 0;
+ }
+ mSecondCombo = new PhoneTypeCombo( mPhoneList, this );
+ mSecondEdit = new KLineEdit( this );
+ mSecondCombo->setLineEdit( mSecondEdit );
+ layout->addWidget( mSecondCombo, x, y++ );
+ layout->addWidget( mSecondEdit, x, y++ );
+
+ y = 0;
+ ++x;
+ mThirdCombo = new PhoneTypeCombo( mPhoneList, this );
+ mThirdEdit = new KLineEdit( this );
+ mThirdCombo->setLineEdit( mThirdEdit );
+ layout->addWidget( mThirdCombo, x, y++ );
+ layout->addWidget( mThirdEdit, x, y++ );
+ if ( QApplication::desktop()->width() < 640 ) {
+ ++x;
+ y = 0;
+ }
+ mFourthCombo = new PhoneTypeCombo( mPhoneList, this );
+ mFourthEdit = new KLineEdit( this );
+ mFourthCombo->setLineEdit( mFourthEdit );
+ layout->addWidget( mFourthCombo, x, y++ );
+ layout->addWidget( mFourthEdit, x, y++ );
+
+ // Four numbers don't fit in the current dialog
+ if ( QApplication::desktop()->width() < 640 ) {
+ mFourthCombo->hide();
+ mFourthEdit->hide();
+ } else {
+ QFontMetrics fm ( font () ) ;
+ int wid = fm.width( "Messenger" ) +60;
+ mPrefCombo->setMaximumWidth( wid );
+ mSecondCombo->setMaximumWidth( wid );
+ mThirdCombo->setMaximumWidth( wid );
+ mFourthCombo->setMaximumWidth( wid );
+ }
+
+
+ connect( mPrefEdit, SIGNAL( textChanged( const QString& ) ),
+ SLOT( slotPrefEditChanged() ) );
+ connect( mSecondEdit, SIGNAL( textChanged( const QString& ) ),
+ SLOT( slotSecondEditChanged() ) );
+ connect( mThirdEdit, SIGNAL( textChanged( const QString& ) ),
+ SLOT( slotThirdEditChanged() ) );
+ connect( mFourthEdit, SIGNAL( textChanged( const QString& ) ),
+ SLOT( slotFourthEditChanged() ) );
+
+ connect( editButton, SIGNAL( clicked() ), SLOT( edit() ) );
+
+ connect( mPrefCombo, SIGNAL( activated( int ) ),
+ SLOT( updatePrefEdit() ) );
+ connect( mSecondCombo, SIGNAL( activated( int ) ),
+ SLOT( updateSecondEdit() ) );
+ connect( mThirdCombo, SIGNAL( activated( int ) ),
+ SLOT( updateThirdEdit() ) );
+ connect( mFourthCombo, SIGNAL( activated( int ) ),
+ SLOT( updateFourthEdit() ) );
+}
+
+PhoneEditWidget::~PhoneEditWidget()
+{
+}
+
+void PhoneEditWidget::setPhoneNumbers( const KABC::PhoneNumber::List &list )
+{
+ mPhoneList.clear();
+
+ // Insert types for existing numbers.
+ mPrefCombo->insertTypeList( list );
+
+ QValueList<int> defaultTypes;
+ defaultTypes << KABC::PhoneNumber::Home;
+ defaultTypes << KABC::PhoneNumber::Work;
+ defaultTypes << KABC::PhoneNumber::Cell;
+ defaultTypes << ( KABC::PhoneNumber::Work | KABC::PhoneNumber::Fax );
+ defaultTypes << ( KABC::PhoneNumber::Home | KABC::PhoneNumber::Fax );
+
+ // Insert default types.
+ // Doing this for mPrefCombo is enough because the list is shared by all
+ // combos.
+ QValueList<int>::ConstIterator it;
+ for( it = defaultTypes.begin(); it != defaultTypes.end(); ++it ) {
+ if ( !mPrefCombo->hasType( *it ) )
+ mPrefCombo->insertType( list, *it, PhoneNumber( "", *it ) );
+ }
+
+ updateCombos();
+
+ mPrefCombo->selectType( defaultTypes[ 0 ] );
+ mSecondCombo->selectType( defaultTypes[ 1 ] );
+ mThirdCombo->selectType( defaultTypes[ 2 ] );
+ mFourthCombo->selectType( defaultTypes[ 3 ] );
+
+ updateLineEdits();
+}
+
+void PhoneEditWidget::updateLineEdits()
+{
+ updatePrefEdit();
+ updateSecondEdit();
+ updateThirdEdit();
+ updateFourthEdit();
+}
+
+void PhoneEditWidget::updateCombos()
+{
+ mPrefCombo->updateTypes();
+ mSecondCombo->updateTypes();
+ mThirdCombo->updateTypes();
+ mFourthCombo->updateTypes();
+}
+
+KABC::PhoneNumber::List PhoneEditWidget::phoneNumbers()
+{
+ KABC::PhoneNumber::List retList;
+
+ KABC::PhoneNumber::List::Iterator it;
+ for ( it = mPhoneList.begin(); it != mPhoneList.end(); ++it )
+ if ( !(*it).number().isEmpty() )
+ retList.append( *it );
+
+ return retList;
+}
+
+void PhoneEditWidget::edit()
+{
+ PhoneEditDialog dlg( mPhoneList, this );
+
+ if ( dlg.exec() ) {
+ if ( dlg.changed() ) {
+ mPhoneList = dlg.phoneNumbers();
+ updateCombos();
+ emit modified();
+ }
+ }
+}
+
+void PhoneEditWidget::updatePrefEdit()
+{
+ updateEdit( mPrefCombo );
+}
+
+void PhoneEditWidget::updateSecondEdit()
+{
+ updateEdit( mSecondCombo );
+}
+
+void PhoneEditWidget::updateThirdEdit()
+{
+ updateEdit( mThirdCombo );
+}
+
+void PhoneEditWidget::updateFourthEdit()
+{
+ updateEdit( mFourthCombo );
+}
+
+void PhoneEditWidget::updateEdit( PhoneTypeCombo *combo )
+{
+ QLineEdit *edit = combo->lineEdit();
+ if ( !edit )
+ return;
+
+#if 0
+ if ( edit == mPrefEdit ) kdDebug(5720) << " prefEdit" << endl;
+ if ( edit == mSecondEdit ) kdDebug(5720) << " secondEdit" << endl;
+ if ( edit == mThirdEdit ) kdDebug(5720) << " thirdEdit" << endl;
+ if ( edit == mFourthEdit ) kdDebug(5720) << " fourthEdit" << endl;
+#endif
+
+ PhoneNumber::List::Iterator it = combo->selectedElement();
+ if ( it != mPhoneList.end() ) {
+ edit->setText( (*it).number() );
+ } else {
+ kdDebug(5720) << "PhoneEditWidget::updateEdit(): no selected element" << endl;
+ }
+}
+
+void PhoneEditWidget::slotPrefEditChanged()
+{
+ updatePhoneNumber( mPrefCombo );
+}
+
+void PhoneEditWidget::slotSecondEditChanged()
+{
+ updatePhoneNumber( mSecondCombo );
+}
+
+void PhoneEditWidget::slotThirdEditChanged()
+{
+ updatePhoneNumber( mThirdCombo );
+}
+
+void PhoneEditWidget::slotFourthEditChanged()
+{
+ updatePhoneNumber( mFourthCombo );
+}
+
+void PhoneEditWidget::updatePhoneNumber( PhoneTypeCombo *combo )
+{
+ QLineEdit *edit = combo->lineEdit();
+ if ( !edit ) return;
+
+ PhoneNumber::List::Iterator it = combo->selectedElement();
+ if ( it != mPhoneList.end() ) {
+ (*it).setNumber( edit->text() );
+ } else {
+ kdDebug(5720) << "PhoneEditWidget::updatePhoneNumber(): no selected element"
+ << endl;
+ }
+
+ updateOtherEdit( combo, mPrefCombo );
+ updateOtherEdit( combo, mSecondCombo );
+ updateOtherEdit( combo, mThirdCombo );
+ updateOtherEdit( combo, mFourthCombo );
+
+ emit modified();
+}
+
+void PhoneEditWidget::updateOtherEdit( PhoneTypeCombo *combo, PhoneTypeCombo *otherCombo )
+{
+ if ( combo == otherCombo ) return;
+
+ if ( combo->currentItem() == otherCombo->currentItem() ) {
+ updateEdit( otherCombo );
+ }
+}
+
+///////////////////////////////////////////
+// PhoneEditDialog
+
+class PhoneViewItem : public QListViewItem
+{
+public:
+ PhoneViewItem( QListView *parent, const KABC::PhoneNumber &number );
+
+ void setPhoneNumber( const KABC::PhoneNumber &number )
+ {
+ mPhoneNumber = number;
+ makeText();
+ }
+
+ QString key() { return mPhoneNumber.id(); }
+ QString country() { return ""; }
+ QString region() { return ""; }
+ QString number() { return ""; }
+
+ KABC::PhoneNumber phoneNumber() { return mPhoneNumber; }
+
+private:
+ void makeText();
+
+ KABC::PhoneNumber mPhoneNumber;
+};
+
+PhoneViewItem::PhoneViewItem( QListView *parent, const KABC::PhoneNumber &number )
+ : QListViewItem( parent ), mPhoneNumber( number )
+{
+ makeText();
+}
+
+void PhoneViewItem::makeText()
+{
+ /**
+ * Will be used in future versions of kaddressbook/libkabc
+
+ setText( 0, mPhoneNumber.country() );
+ setText( 1, mPhoneNumber.region() );
+ setText( 2, mPhoneNumber.number() );
+ setText( 3, mPhoneNumber.typeLabel() );
+ */
+
+ setText( 0, mPhoneNumber.number() );
+ setText( 1, mPhoneNumber.typeLabel() );
+}
+
+PhoneEditDialog::PhoneEditDialog( const KABC::PhoneNumber::List &list, QWidget *parent, const char *name )
+ : KDialogBase( KDialogBase::Plain, i18n( "Edit Phone Numbers" ),
+ KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok,
+ parent, name, true)
+{
+ mPhoneNumberList = list;
+
+ QWidget *page = plainPage();
+
+ QGridLayout *layout = new QGridLayout( page, 1, 2 );
+ layout->setSpacing( spacingHint() );
+
+ mListView = new KListView( page );
+ mListView->setAllColumnsShowFocus( true );
+ mListView->addColumn( i18n( "Number" ) );
+ mListView->addColumn( i18n( "Type" ) );
+
+ KButtonBox *buttonBox = new KButtonBox( page, Vertical );
+
+ buttonBox->addButton( i18n( "&Add..." ), this, SLOT( slotAddPhoneNumber() ) );
+ mEditButton = buttonBox->addButton( i18n( "&Edit..." ), this, SLOT( slotEditPhoneNumber() ) );
+ mEditButton->setEnabled( false );
+ mRemoveButton = buttonBox->addButton( i18n( "&Remove" ), this, SLOT( slotRemovePhoneNumber() ) );
+ mRemoveButton->setEnabled( false );
+ buttonBox->layout();
+
+ layout->addWidget( mListView, 0, 0 );
+ layout->addWidget( buttonBox, 0, 1 );
+
+ connect( mListView, SIGNAL(selectionChanged()), SLOT(slotSelectionChanged()) );
+ connect( mListView, SIGNAL(doubleClicked( QListViewItem *, const QPoint &, int )), this, SLOT( slotEditPhoneNumber()));
+
+ KABC::PhoneNumber::List::Iterator it;
+ for ( it = mPhoneNumberList.begin(); it != mPhoneNumberList.end(); ++it )
+ new PhoneViewItem( mListView, *it );
+
+ mChanged = false;
+}
+
+PhoneEditDialog::~PhoneEditDialog()
+{
+}
+
+void PhoneEditDialog::slotAddPhoneNumber()
+{
+ KABC::PhoneNumber tmp( "", 0 );
+ PhoneTypeDialog dlg( tmp, this );
+
+ if ( dlg.exec() ) {
+ KABC::PhoneNumber phoneNumber = dlg.phoneNumber();
+ mPhoneNumberList.append( phoneNumber );
+ new PhoneViewItem( mListView, phoneNumber );
+
+ mChanged = true;
+ }
+}
+
+void PhoneEditDialog::slotRemovePhoneNumber()
+{
+ PhoneViewItem *item = static_cast<PhoneViewItem*>( mListView->currentItem() );
+ if ( !item )
+ return;
+
+ mPhoneNumberList.remove( item->phoneNumber() );
+ QListViewItem *currItem = mListView->currentItem();
+ mListView->takeItem( currItem );
+ delete currItem;
+
+ mChanged = true;
+}
+
+void PhoneEditDialog::slotEditPhoneNumber()
+{
+ PhoneViewItem *item = static_cast<PhoneViewItem*>( mListView->currentItem() );
+ if ( !item )
+ return;
+
+ PhoneTypeDialog dlg( item->phoneNumber(), this );
+
+ if ( dlg.exec() ) {
+ slotRemovePhoneNumber();
+ KABC::PhoneNumber phoneNumber = dlg.phoneNumber();
+ mPhoneNumberList.append( phoneNumber );
+ new PhoneViewItem( mListView, phoneNumber );
+
+ mChanged = true;
+ }
+}
+
+void PhoneEditDialog::slotSelectionChanged()
+{
+ bool state = ( mListView->currentItem() != 0 );
+
+ mRemoveButton->setEnabled( state );
+ mEditButton->setEnabled( state );
+}
+
+const KABC::PhoneNumber::List &PhoneEditDialog::phoneNumbers()
+{
+ return mPhoneNumberList;
+}
+
+bool PhoneEditDialog::changed() const
+{
+ return mChanged;
+}
+
+///////////////////////////////////////////
+// PhoneTypeDialog
+PhoneTypeDialog::PhoneTypeDialog( const KABC::PhoneNumber &phoneNumber,
+ QWidget *parent, const char *name)
+ : KDialogBase( KDialogBase::Plain, i18n( "Edit Phone Number" ),
+ KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok,
+ parent, name, true), mPhoneNumber( phoneNumber )
+{
+ QWidget *page = plainPage();
+ QLabel *label = 0;
+ QGridLayout *layout = new QGridLayout( page, 3, 2, marginHint(), spacingHint() );
+
+ label = new QLabel( i18n( "Number:" ), page );
+ layout->addWidget( label, 0, 0 );
+ mNumber = new KLineEdit( page );
+ layout->addWidget( mNumber, 0, 1 );
+
+ mPreferredBox = new QCheckBox( i18n( "This is the preferred phone number" ), page );
+ layout->addMultiCellWidget( mPreferredBox, 1, 1, 0, 1 );
+
+ mGroup = new QButtonGroup( 2, Horizontal, i18n( "Types" ), page );
+ layout->addMultiCellWidget( mGroup, 2, 2, 0, 1 );
+
+ // fill widgets
+ mNumber->setText( mPhoneNumber.number() );
+
+ mTypeList = KABC::PhoneNumber::typeList();
+ mTypeList.remove( KABC::PhoneNumber::Pref );
+
+ KABC::PhoneNumber::TypeList::Iterator it;
+ for ( it = mTypeList.begin(); it != mTypeList.end(); ++it )
+ new QCheckBox( KABC::PhoneNumber::typeLabel( *it ), mGroup );
+
+ for ( int i = 0; i < mGroup->count(); ++i ) {
+ int type = mPhoneNumber.type();
+ QCheckBox *box = (QCheckBox*)mGroup->find( i );
+ box->setChecked( type & mTypeList[ i ] );
+ }
+
+ mPreferredBox->setChecked( mPhoneNumber.type() & KABC::PhoneNumber::Pref );
+}
+
+KABC::PhoneNumber PhoneTypeDialog::phoneNumber()
+{
+ mPhoneNumber.setNumber( mNumber->text() );
+
+ int type = 0;
+ for ( int i = 0; i < mGroup->count(); ++i ) {
+ QCheckBox *box = (QCheckBox*)mGroup->find( i );
+ if ( box->isChecked() )
+ type += mTypeList[ i ];
+ }
+
+ if ( mPreferredBox->isChecked() )
+ mPhoneNumber.setType( type | KABC::PhoneNumber::Pref );
+ else
+ mPhoneNumber.setType( type & ~KABC::PhoneNumber::Pref );
+
+ return mPhoneNumber;
+}
+
+#ifndef KAB_EMBEDDED
+#include "phoneeditwidget.moc"
+#endif //KAB_EMBEDDED
diff --git a/kaddressbook/phoneeditwidget.h b/kaddressbook/phoneeditwidget.h
new file mode 100644
index 0000000..7fe4bc0
--- a/dev/null
+++ b/kaddressbook/phoneeditwidget.h
@@ -0,0 +1,147 @@
+#ifndef PHONEEDITWIDGET_H
+#define PHONEEDITWIDGET_H
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include <kdialogbase.h>
+
+#include "addresseeconfig.h"
+#include "typecombo.h"
+
+class QButtonGroup;
+class QCheckBox;
+
+class KListView;
+class KLineEdit;
+class KComboBox;
+
+typedef TypeCombo<KABC::PhoneNumber> PhoneTypeCombo;
+
+/**
+ Widget for editing phone numbers.
+*/
+class PhoneEditWidget : public QWidget
+{
+ Q_OBJECT
+
+ public:
+ PhoneEditWidget( QWidget *parent, const char *name = 0 );
+ ~PhoneEditWidget();
+
+ void setPhoneNumbers( const KABC::PhoneNumber::List &list );
+ KABC::PhoneNumber::List phoneNumbers();
+
+ void updateTypeCombo( const KABC::PhoneNumber::List&, KComboBox* );
+ KABC::PhoneNumber currentPhoneNumber( KComboBox*, int );
+
+ signals:
+ void modified();
+
+ private slots:
+ void edit();
+
+ void updatePrefEdit();
+ void updateSecondEdit();
+ void updateThirdEdit();
+ void updateFourthEdit();
+
+ void slotPrefEditChanged();
+ void slotSecondEditChanged();
+ void slotThirdEditChanged();
+ void slotFourthEditChanged();
+
+ protected:
+ void updateLineEdits();
+ void updateCombos();
+
+ private:
+ void updateEdit( PhoneTypeCombo *combo );
+ void updatePhoneNumber( PhoneTypeCombo *combo );
+ void updateOtherEdit( PhoneTypeCombo *combo, PhoneTypeCombo *otherCombo );
+
+ PhoneTypeCombo *mPrefCombo;
+ PhoneTypeCombo *mSecondCombo;
+ PhoneTypeCombo *mThirdCombo;
+ PhoneTypeCombo *mFourthCombo;
+
+ KLineEdit *mPrefEdit;
+ KLineEdit *mSecondEdit;
+ KLineEdit *mThirdEdit;
+ KLineEdit *mFourthEdit;
+
+ KABC::PhoneNumber::List mPhoneList;
+};
+
+/**
+ Dialog for editing lists of phonenumbers.
+*/
+class PhoneEditDialog : public KDialogBase
+{
+ Q_OBJECT
+
+ public:
+ PhoneEditDialog( const KABC::PhoneNumber::List &list, QWidget *parent, const char *name = 0 );
+ ~PhoneEditDialog();
+
+ const KABC::PhoneNumber::List &phoneNumbers();
+ bool changed() const;
+
+ protected slots:
+ void slotAddPhoneNumber();
+ void slotRemovePhoneNumber();
+ void slotEditPhoneNumber();
+ void slotSelectionChanged();
+
+ private:
+ KABC::PhoneNumber::List mPhoneNumberList;
+ KABC::PhoneNumber::TypeList mTypeList;
+ KComboBox *mTypeBox;
+ KListView *mListView;
+
+ QPushButton *mRemoveButton;
+ QPushButton *mEditButton;
+
+ bool mChanged;
+};
+
+/**
+ Dialog for editing phone number types.
+*/
+class PhoneTypeDialog : public KDialogBase
+{
+ Q_OBJECT
+public:
+ PhoneTypeDialog( const KABC::PhoneNumber &phoneNumber, QWidget *parent, const char *name = 0 );
+
+ KABC::PhoneNumber phoneNumber();
+
+private:
+ KABC::PhoneNumber mPhoneNumber;
+ KABC::PhoneNumber::TypeList mTypeList;
+
+ QButtonGroup *mGroup;
+ QCheckBox *mPreferredBox;
+ KLineEdit *mNumber;
+};
+
+#endif
diff --git a/kaddressbook/secrecywidget.cpp b/kaddressbook/secrecywidget.cpp
new file mode 100644
index 0000000..4a2acc8
--- a/dev/null
+++ b/kaddressbook/secrecywidget.cpp
@@ -0,0 +1,70 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include <qlayout.h>
+
+#include <kabc/secrecy.h>
+#include <kcombobox.h>
+#include <kdialog.h>
+
+#include "secrecywidget.h"
+
+SecrecyWidget::SecrecyWidget( QWidget *parent, const char *name )
+ : QWidget( parent, name )
+{
+ QVBoxLayout *layout = new QVBoxLayout( this, KDialog::marginHint(),
+ KDialog::spacingHint() );
+ mSecrecyCombo = new KComboBox( this );
+ layout->addWidget( mSecrecyCombo );
+
+ KABC::Secrecy::TypeList list = KABC::Secrecy::typeList();
+ KABC::Secrecy::TypeList::Iterator it;
+ for ( it = list.begin(); it != list.end(); ++it )
+ mSecrecyCombo->insertItem( KABC::Secrecy::typeLabel( *it ), *it );
+
+ connect( mSecrecyCombo, SIGNAL( activated( const QString& ) ),
+ SIGNAL( changed() ) );
+}
+
+SecrecyWidget::~SecrecyWidget()
+{
+}
+
+void SecrecyWidget::setSecrecy( const KABC::Secrecy &secrecy )
+{
+//US to avoid an indexoutofbounds error if value is invalid
+ if (secrecy.isValid())
+ mSecrecyCombo->setCurrentItem( secrecy.type() );
+}
+
+KABC::Secrecy SecrecyWidget::secrecy() const
+{
+ KABC::Secrecy secrecy;
+ secrecy.setType( mSecrecyCombo->currentItem() );
+
+ return secrecy;
+}
+
+#ifndef KAB_EMBEDDED
+#include "secrecywidget.moc"
+#endif //KAB_EMBEDDED
diff --git a/kaddressbook/secrecywidget.h b/kaddressbook/secrecywidget.h
new file mode 100644
index 0000000..96e6905
--- a/dev/null
+++ b/kaddressbook/secrecywidget.h
@@ -0,0 +1,50 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef SECRECYWIDGET_H
+#define SECRECYWIDGET_H
+
+#include <qwidget.h>
+
+namespace KABC { class Secrecy; }
+class KComboBox;
+
+class SecrecyWidget : public QWidget
+{
+ Q_OBJECT
+
+ public:
+ SecrecyWidget( QWidget *parent, const char *name = 0 );
+ ~SecrecyWidget();
+
+ void setSecrecy( const KABC::Secrecy &secrecy );
+ KABC::Secrecy secrecy() const;
+
+ signals:
+ void changed();
+
+ private:
+ KComboBox *mSecrecyCombo;
+};
+
+#endif
diff --git a/kaddressbook/typecombo.h b/kaddressbook/typecombo.h
new file mode 100644
index 0000000..191273d
--- a/dev/null
+++ b/kaddressbook/typecombo.h
@@ -0,0 +1,193 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef TYPECOMBO_H
+#define TYPECOMBO_H
+
+#include <kabc/phonenumber.h>
+#include <kcombobox.h>
+
+/**
+ Combo box for type information of Addresses and Phone numbers.
+*/
+template <class T>
+class TypeCombo : public KComboBox
+{
+ public:
+ typedef typename T::List List;
+ typedef typename T::List::Iterator Iterator;
+
+ TypeCombo( List &list, QWidget *parent, const char *name = 0 );
+
+ void setLineEdit( QLineEdit *edit ) { mLineEdit = edit; }
+ QLineEdit *lineEdit() const { return mLineEdit; }
+
+ void updateTypes();
+
+ void selectType( int type );
+
+ int selectedType();
+
+ Iterator selectedElement();
+
+ void insertType( const List &list, int type,
+ const T &defaultObject );
+ void insertTypeList( const List &list );
+
+ bool hasType( int type );
+
+ private:
+ List &mTypeList;
+ QLineEdit *mLineEdit;
+};
+
+template <class T>
+#ifdef _WIN32_
+TypeCombo<T>::TypeCombo( typename TypeCombo::List &list, QWidget *parent,
+#else
+TypeCombo<T>::TypeCombo( TypeCombo::List &list, QWidget *parent,
+
+#endif
+ const char *name )
+ : KComboBox( parent),
+//US my kde version has no KComboBox constructor witgh two parameters
+//US : KComboBox( parent, name ),
+ mTypeList( list )
+{
+}
+
+template <class T>
+void TypeCombo<T>::updateTypes()
+{
+ // Remember current item
+ QString currentId;
+ int current = currentItem();
+ if ( current >= 0 ) currentId = mTypeList[ current ].id();
+
+ clear();
+
+ QMap<int,int> labelCount;
+
+ uint i;
+ for( i = 0; i < mTypeList.count(); ++i ) {
+ int type = ( mTypeList[ i ].type() & ~( T::Pref ) );
+ QString label = mTypeList[ i ].typeLabel( type );
+ int count = 1;
+ if ( labelCount.contains( type ) ) {
+ count = labelCount[ type ] + 1;
+ }
+ labelCount[ type ] = count;
+ if ( count > 1 ) {
+ label = i18n("label (number)", "%1 (%2)").arg( label )
+ .arg( QString::number( count ) );
+ }
+ insertItem( label );
+ }
+
+ // Restore previous current item
+ if ( !currentId.isEmpty() ) {
+ for( i = 0; i < mTypeList.count(); ++i ) {
+ if ( mTypeList[ i ].id() == currentId ) {
+ setCurrentItem( i );
+ break;
+ }
+ }
+ }
+}
+
+template <class T>
+void TypeCombo<T>::selectType( int type )
+{
+ uint i;
+ for( i = 0; i < mTypeList.count(); ++i ) {
+ if ( (mTypeList[ i ].type() & ~T::Pref) == type ) {
+ setCurrentItem( i );
+ break;
+ }
+ }
+}
+
+template <class T>
+int TypeCombo<T>::selectedType()
+{
+ return mTypeList[ currentItem() ].type();
+}
+
+template <class T>
+typename TypeCombo<T>::Iterator TypeCombo<T>::selectedElement()
+{
+ return mTypeList.at( currentItem() );
+}
+
+template <class T>
+#ifdef _WIN32_
+void TypeCombo<T>::insertType( typename const TypeCombo::List &list, int type,
+#else
+void TypeCombo<T>::insertType( const TypeCombo::List &list, int type,
+#endif
+ const T &defaultObject )
+{
+ uint i;
+ for ( i = 0; i < list.count(); ++i ) {
+ if ( list[ i ].type() == type ) {
+ mTypeList.append( list[ i ] );
+ break;
+ }
+ }
+ if ( i == list.count() ) {
+ mTypeList.append( defaultObject );
+ }
+}
+
+template <class T>
+#ifdef _WIN32_
+void TypeCombo<T>::insertTypeList( typename const TypeCombo::List &list )
+#else
+void TypeCombo<T>::insertTypeList( const TypeCombo::List &list )
+
+#endif
+{
+ uint i;
+ for ( i = 0; i < list.count(); ++i ) {
+ uint j;
+ for( j = 0; j < mTypeList.count(); ++j ) {
+ if ( list[ i ].id() == mTypeList[ j ].id() ) break;
+ }
+ if ( j == mTypeList.count() ) {
+ mTypeList.append( list[ i ] );
+ }
+ }
+}
+
+template <class T>
+bool TypeCombo<T>::hasType( int type )
+{
+ for( uint i = 0; i < mTypeList.count(); ++i ) {
+ if ( ( mTypeList[ i ].type() & ~T::Pref ) == type )
+ return true;
+ }
+
+ return false;
+}
+
+#endif
diff --git a/kaddressbook/undo.cpp b/kaddressbook/undo.cpp
new file mode 100644
index 0000000..4442087
--- a/dev/null
+++ b/kaddressbook/undo.cpp
@@ -0,0 +1,119 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (C) 1999 Don Sanders <sanders@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include "undo.h"
+
+///////////////////////////////
+// StackBase
+
+void StackBase::push(Command *c)
+{
+ mCommandStack.push(c);
+ emit changed();
+}
+
+bool StackBase::isEmpty()
+{
+ return mCommandStack.isEmpty();
+}
+
+Command *StackBase::top()
+{
+ return mCommandStack.top();
+}
+
+void StackBase::clear()
+{
+ mCommandStack.clear();
+ emit changed();
+}
+
+Command *StackBase::pop()
+{
+ Command *c = mCommandStack.pop();
+ if (c)
+ emit changed();
+
+ return c;
+}
+
+///////////////////////////////
+// UndoStack
+
+UndoStack* UndoStack::instance_ = 0;
+
+UndoStack::UndoStack()
+ : StackBase()
+{
+ // setAutoDelete( true );
+}
+
+UndoStack* UndoStack::instance()
+{
+ if (!instance_)
+ instance_ = new UndoStack();
+ return instance_;
+}
+
+void UndoStack::undo()
+{
+ if (isEmpty())
+ return;
+
+ Command *command = pop();
+ command->undo();
+
+ RedoStack::instance()->push( command );
+}
+
+////////////////////
+// RedoStack
+
+RedoStack* RedoStack::instance_ = 0;
+
+RedoStack::RedoStack()
+{
+ mCommandStack.setAutoDelete( true );
+}
+
+RedoStack* RedoStack::instance()
+{
+ if (!instance_)
+ instance_ = new RedoStack();
+ return instance_;
+}
+
+void RedoStack::redo()
+{
+ Command *command;
+ if (isEmpty())
+ return;
+
+ command = pop();
+ command->redo();
+ UndoStack::instance()->push( command );
+}
+
+#ifndef KAB_EMBEDDED
+#include "undo.moc"
+#endif //KAB_EMBEDDED
diff --git a/kaddressbook/undo.h b/kaddressbook/undo.h
new file mode 100644
index 0000000..843bc26
--- a/dev/null
+++ b/kaddressbook/undo.h
@@ -0,0 +1,95 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (C) 1999 Don Sanders <sanders@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef UNDO_H
+#define UNDO_H
+
+#include <qobject.h>
+#include <qptrstack.h>
+#include <qstring.h>
+
+class Command
+{
+public:
+ Command() {}
+ virtual ~Command() {};
+ virtual QString name() = 0;
+ virtual void redo() = 0; // egcs requires these methods to have
+ virtual void undo() = 0; // implementations (Seems like a bug)
+ // pure virtual may not work
+};
+
+/** The Undo and Redo stacks now no longer inherit directly from a stack.
+* They now contain a stack internally and inherit from StackBase, which
+* has a signal for when the stack is modified. This is need to keep
+* the edit menu and toolbar up to date.
+*
+* Really this is a simple observable stack.
+*/
+class StackBase : public QObject
+{
+ Q_OBJECT
+
+ public:
+ StackBase() : QObject() {}
+
+ void push(Command *c);
+ bool isEmpty();
+ Command *top();
+ void clear();
+
+ signals:
+ void changed();
+
+ protected:
+ /** Protect the pop method so users must call undo/redo to properly
+ * use the stack, however the subclasses need it to modify the stack.
+ */
+ Command *pop();
+
+ QPtrStack<Command> mCommandStack;
+};
+
+class UndoStack : public StackBase
+{
+public:
+ static UndoStack *instance();
+ void undo();
+
+protected:
+ UndoStack();
+ static UndoStack* instance_;
+};
+
+class RedoStack : public StackBase
+{
+public:
+ static RedoStack *instance();
+ void redo();
+
+protected:
+ RedoStack();
+ static RedoStack* instance_;
+};
+
+#endif
diff --git a/kaddressbook/undocmds.cpp b/kaddressbook/undocmds.cpp
new file mode 100644
index 0000000..db773be
--- a/dev/null
+++ b/kaddressbook/undocmds.cpp
@@ -0,0 +1,240 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (C) 1999 Don Sanders <sanders@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include <qtextstream.h>
+
+#include <qapplication.h>
+#include <qclipboard.h>
+
+#include <klocale.h>
+#include <kdebug.h>
+#include <kapplication.h>
+#include <kabc/addressbook.h>
+
+#include "addresseeutil.h"
+#include "addresseeconfig.h"
+#include "kabcore.h"
+
+#include "undocmds.h"
+
+/////////////////////////////////
+// PwDelete Methods
+
+PwDeleteCommand::PwDeleteCommand(KABC::AddressBook *doc,
+ const QStringList &uidList)
+ : Command(), mDocument(doc), mAddresseeList(), mUidList(uidList)
+{
+ redo();
+}
+
+PwDeleteCommand::~PwDeleteCommand()
+{
+}
+
+QString PwDeleteCommand::name()
+{
+ return i18n( "Delete" );
+}
+
+void PwDeleteCommand::undo()
+{
+ // Put it back in the document
+ KABC::Addressee::List::Iterator iter;
+ for (iter = mAddresseeList.begin(); iter != mAddresseeList.end(); ++iter)
+ {
+ mDocument->insertAddressee(*iter);
+ }
+
+ mAddresseeList.clear();
+}
+
+void PwDeleteCommand::redo()
+{
+ // Just remove it from the document. This is enough to make the user
+ // Think the item has been deleted
+ KABC::Addressee a;
+ QStringList::Iterator iter;
+ for (iter = mUidList.begin(); iter != mUidList.end(); ++iter)
+ {
+ a = mDocument->findByUid(*iter);
+ mDocument->removeAddressee(a);
+ mAddresseeList.append(a);
+ AddresseeConfig::instance()->remove(a.uid());
+ }
+}
+
+/////////////////////////////////
+// PwPaste Methods
+
+PwPasteCommand::PwPasteCommand( KABCore *core, const KABC::Addressee::List &list )
+ : Command(), mCore( core ), mAddresseeList( list )
+{
+ redo();
+}
+
+QString PwPasteCommand::name()
+{
+ return i18n( "Paste" );
+}
+
+void PwPasteCommand::undo()
+{
+ KABC::Addressee::List::Iterator it;
+ for ( it = mAddresseeList.begin(); it != mAddresseeList.end(); ++it )
+ mCore->addressBook()->removeAddressee( *it );
+}
+
+void PwPasteCommand::redo()
+{
+ QStringList uids;
+ KABC::Addressee::List::Iterator it;
+ for ( it = mAddresseeList.begin(); it != mAddresseeList.end(); ++it ) {
+ /* we have to set a new uid for the contact, otherwise insertAddressee()
+ ignore it.
+ */
+ (*it).setUid( KApplication::randomString( 10 ) );
+ uids.append( (*it).uid() );
+ mCore->addressBook()->insertAddressee( *it );
+ }
+
+ QStringList::Iterator uidIt;
+ for ( uidIt = uids.begin(); uidIt != uids.end(); ++uidIt )
+ mCore->editContact( *uidIt );
+}
+
+/////////////////////////////////
+// PwNew Methods
+
+PwNewCommand::PwNewCommand( KABC::AddressBook *doc, const KABC::Addressee &a )
+ : Command(), mDocument( doc ), mA( a )
+{
+ mDocument->insertAddressee(mA);
+}
+
+PwNewCommand::~PwNewCommand()
+{
+}
+
+QString PwNewCommand::name()
+{
+ return i18n( "New Contact" );
+}
+
+void PwNewCommand::undo()
+{
+ mDocument->removeAddressee( mA );
+}
+
+void PwNewCommand::redo()
+{
+ mDocument->insertAddressee( mA );
+}
+
+/////////////////////////////////
+// PwEdit Methods
+
+PwEditCommand::PwEditCommand(KABC::AddressBook *doc,
+ const KABC::Addressee &oldA,
+ const KABC::Addressee &newA )
+ : Command(), mDocument(doc), mOldA(oldA), mNewA(newA)
+{
+ redo();
+}
+
+PwEditCommand::~PwEditCommand()
+{
+}
+
+QString PwEditCommand::name()
+{
+ return i18n( "Entry Edit" );
+}
+
+void PwEditCommand::undo()
+{
+ mDocument->insertAddressee(mOldA);
+}
+
+void PwEditCommand::redo()
+{
+ mDocument->insertAddressee(mNewA);
+}
+
+/////////////////////////////////
+// PwCut Methods
+
+PwCutCommand::PwCutCommand(KABC::AddressBook *doc, const QStringList &uidList)
+ : Command(), mDocument(doc), mAddresseeList(), mUidList(uidList),
+ mClipText(), mOldText()
+{
+ redo();
+}
+
+QString PwCutCommand::name()
+{
+ return i18n( "Cut" );
+}
+
+void PwCutCommand::undo()
+{
+ KABC::Addressee::List::Iterator iter;
+ for (iter = mAddresseeList.begin(); iter != mAddresseeList.end(); ++iter)
+ {
+ mDocument->insertAddressee(*iter);
+ }
+ mAddresseeList.clear();
+
+ QClipboard *cb = QApplication::clipboard();
+//US
+#ifndef KAB_EMBEDDED
+ kapp->processEvents();
+#else //KAB_EMBEDDED
+ qApp->processEvents();
+#endif //KAB_EMBEDDED
+ cb->setText( mOldText );
+}
+
+void PwCutCommand::redo()
+{
+ KABC::Addressee a;
+ QStringList::Iterator iter;
+ for (iter = mUidList.begin(); iter != mUidList.end(); ++iter)
+ {
+ a = mDocument->findByUid(*iter);
+ mDocument->removeAddressee(a);
+ mAddresseeList.append(a);
+ }
+
+ // Convert to clipboard
+ mClipText = AddresseeUtil::addresseesToClipboard(mAddresseeList);
+
+ QClipboard *cb = QApplication::clipboard();
+ mOldText = cb->text();
+//US
+#ifndef KAB_EMBEDDED
+ kapp->processEvents();
+#else //KAB_EMBEDDED
+ qApp->processEvents();
+#endif //KAB_EMBEDDED
+ cb->setText( mClipText );
+}
diff --git a/kaddressbook/undocmds.h b/kaddressbook/undocmds.h
new file mode 100644
index 0000000..c3f23cc
--- a/dev/null
+++ b/kaddressbook/undocmds.h
@@ -0,0 +1,117 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (C) 1999 Don Sanders <sanders@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef UNDOCMDS_H
+#define UNDOCMDS_H
+//
+// Commands for undo/redo functionality.
+
+#include <qstring.h>
+#include <qstringlist.h>
+
+#include <kabc/addressee.h>
+
+#include "undo.h"
+
+namespace KABC {
+ class AddressBook;
+}
+
+class KABCore;
+
+class PwDeleteCommand : public Command
+{
+public:
+ PwDeleteCommand(KABC::AddressBook *doc, const QStringList &uidList );
+ virtual ~PwDeleteCommand();
+ virtual QString name();
+ virtual void undo();
+ virtual void redo();
+
+private:
+ KABC::AddressBook *mDocument;
+ KABC::Addressee::List mAddresseeList;
+ QStringList mUidList;
+};
+
+class PwPasteCommand : public Command
+{
+ public:
+ PwPasteCommand( KABCore *core, const KABC::Addressee::List &list );
+ virtual QString name();
+ virtual void undo();
+ virtual void redo();
+
+ private:
+ KABCore *mCore;
+ KABC::Addressee::List mAddresseeList;
+};
+
+class PwCutCommand : public Command
+{
+public:
+ PwCutCommand(KABC::AddressBook *doc, const QStringList &uidList);
+ virtual QString name();
+ virtual void undo();
+ virtual void redo();
+
+private:
+ KABC::AddressBook *mDocument;
+ KABC::Addressee::List mAddresseeList;
+ QStringList mUidList;
+ QString mClipText;
+ QString mOldText;
+};
+
+class PwNewCommand : public Command
+{
+public:
+ PwNewCommand(KABC::AddressBook *doc, const KABC::Addressee &a );
+ ~PwNewCommand();
+ virtual QString name();
+ virtual void undo();
+ virtual void redo();
+
+private:
+ KABC::AddressBook *mDocument;
+ KABC::Addressee mA;
+};
+
+class PwEditCommand : public Command
+{
+public:
+ PwEditCommand(KABC::AddressBook *doc,
+ const KABC::Addressee &oldA,
+ const KABC::Addressee &newA);
+ virtual ~PwEditCommand();
+ virtual QString name();
+ virtual void undo();
+ virtual void redo();
+
+private:
+ KABC::AddressBook *mDocument;
+ KABC::Addressee mOldA;
+ KABC::Addressee mNewA;
+};
+
+#endif
diff --git a/kaddressbook/viewconfigurefieldspage.cpp b/kaddressbook/viewconfigurefieldspage.cpp
new file mode 100644
index 0000000..2c827eb
--- a/dev/null
+++ b/kaddressbook/viewconfigurefieldspage.cpp
@@ -0,0 +1,345 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef KAB_EMBEDDED
+#include <kcombobox.h>
+#include <qpushbutton.h>
+#include <kdebug.h>
+
+#else //KAB_EMBEDDED
+#include <qcombobox.h>
+#endif //KAB_EMBEDDED
+
+#include <kiconloader.h>
+#include <kdialog.h>
+#include <klocale.h>
+
+#include <qtoolbutton.h>
+#include <qlabel.h>
+#include <qlistbox.h>
+#include <qlayout.h>
+
+#include "viewconfigurefieldspage.h"
+
+class FieldItem : public QListBoxText
+{
+ public:
+ FieldItem( QListBox *parent, KABC::Field *field )
+ : QListBoxText( parent, field->label() ), mField( field ) {}
+
+ FieldItem( QListBox *parent, KABC::Field *field, int index )
+ : QListBoxText( parent, field->label(), parent->item( index ) ),
+ mField( field ) {}
+
+ KABC::Field *field() { return mField; }
+
+ private:
+ KABC::Field *mField;
+};
+
+
+ViewConfigureFieldsPage::ViewConfigureFieldsPage( KABC::AddressBook *ab,
+ QWidget *parent,
+ const char *name )
+ : QWidget( parent, name ), mAddressBook( ab )
+{
+ initGUI();
+}
+
+void ViewConfigureFieldsPage::restoreSettings( KConfig *config )
+{
+ KABC::Field::List fields = KABC::Field::restoreFields( config, "KABCFields" );
+
+ if ( fields.isEmpty() )
+ fields = KABC::Field::defaultFields();
+
+ KABC::Field::List::ConstIterator it;
+ for( it = fields.begin(); it != fields.end(); ++it )
+ new FieldItem( mSelectedBox, *it );
+
+ slotShowFields( mCategoryCombo->currentItem() );
+}
+
+void ViewConfigureFieldsPage::saveSettings( KConfig *config )
+{
+ KABC::Field::List fields;
+
+ for( uint i = 0; i < mSelectedBox->count(); ++i ) {
+ FieldItem *fieldItem = static_cast<FieldItem *>( mSelectedBox->item( i ) );
+ fields.append( fieldItem->field() );
+ }
+
+ KABC::Field::saveFields( config, "KABCFields", fields );
+}
+
+void ViewConfigureFieldsPage::slotShowFields( int index )
+{
+ int currentPos = mUnSelectedBox->currentItem();
+ mUnSelectedBox->clear();
+
+ int category;
+ if ( index == 0 ) category = KABC::Field::All;
+ else category = 1 << ( index - 1 );
+
+ KABC::Field::List allFields = mAddressBook->fields( category );
+
+ KABC::Field::List::ConstIterator it;
+ for ( it = allFields.begin(); it != allFields.end(); ++it ) {
+ QListBoxItem *item = mSelectedBox->firstItem();
+ while( item ) {
+ FieldItem *fieldItem = static_cast<FieldItem *>( item );
+ if ( (*it)->equals( fieldItem->field() ) )
+ break;
+ item = item->next();
+ }
+
+ if ( !item )
+ new FieldItem( mUnSelectedBox, *it );
+ }
+
+ mUnSelectedBox->sort();
+ mUnSelectedBox->setCurrentItem( currentPos );
+}
+
+void ViewConfigureFieldsPage::slotSelect()
+{
+ // insert selected items in the unselected list to the selected list,
+ // directoy under the current item if selected, or at the bottonm if
+ // nothing is selected in the selected list
+ int where = mSelectedBox->currentItem();
+//US QListBoxItem::isSelected()) is not available in QT 2.x. Use selected instead.
+ if ( !(where > -1 && mSelectedBox->item( where )->selected()) )
+ where = mSelectedBox->count() - 1;
+
+ for ( uint i = 0; i < mUnSelectedBox->count(); ++i )
+ if ( mUnSelectedBox->isSelected( mUnSelectedBox->item( i ) ) ) {
+ FieldItem *fieldItem = static_cast<FieldItem *>( mUnSelectedBox->item( i ) );
+ new FieldItem( mSelectedBox, fieldItem->field(), where );
+ where++;
+ }
+
+ slotShowFields( mCategoryCombo->currentItem() );
+}
+
+void ViewConfigureFieldsPage::slotUnSelect()
+{
+ for ( uint i = 0; i < mSelectedBox->count(); ++i )
+ if ( mSelectedBox->isSelected( mSelectedBox->item( i ) ) ) {
+ mSelectedBox->removeItem( i );
+ --i;
+ }
+
+ slotShowFields( mCategoryCombo->currentItem() );
+}
+
+void ViewConfigureFieldsPage::slotButtonsEnabled()
+{
+ bool state = false;
+ // add button: enabled if any items are selected in the unselected list
+ for( uint i = 0; i < mUnSelectedBox->count(); ++i )
+//US QListBoxItem::isSelected()) is not available in QT 2.x. Use selected instead.
+ if ( mUnSelectedBox->item( i )->selected() ) {
+ state = true;
+ break;
+ }
+ mAddButton->setEnabled( state );
+
+ int j = mSelectedBox->currentItem();
+ state = ( j > -1 && mSelectedBox->isSelected( j ) );
+
+ // up button: enabled if there is a current item > 0 and that is selected
+ mUpButton->setEnabled( ( j > 0 && state ) );
+
+ // down button: enabled if there is a current item < count - 2 and that is selected
+ mDownButton->setEnabled( ( j > -1 && j < (int)mSelectedBox->count() - 1 && state ) );
+
+ // remove button: enabled if any items are selected in the selected list
+ state = false;
+ for ( uint i = 0; i < mSelectedBox->count(); ++i )
+//US QListBoxItem::isSelected()) is not available in QT 2.x. Use selected instead.
+ if ( mSelectedBox->item( i )->selected() ) {
+ state = true;
+ break;
+ }
+ mRemoveButton->setEnabled( state );
+}
+
+void ViewConfigureFieldsPage::slotMoveUp()
+{
+ int i = mSelectedBox->currentItem();
+ if ( i > 0 ) {
+ QListBoxItem *item = mSelectedBox->item( i );
+ mSelectedBox->takeItem( item );
+ mSelectedBox->insertItem( item, i - 1 );
+ mSelectedBox->setCurrentItem( item );
+ mSelectedBox->setSelected( i - 1, true );
+ }
+}
+
+void ViewConfigureFieldsPage::slotMoveDown()
+{
+ int i = mSelectedBox->currentItem();
+ if ( i > -1 && i < (int)mSelectedBox->count() - 1 ) {
+ QListBoxItem *item = mSelectedBox->item( i );
+ mSelectedBox->takeItem( item );
+ mSelectedBox->insertItem( item, i + 1 );
+ mSelectedBox->setCurrentItem( item );
+ mSelectedBox->setSelected( i + 1, true );
+ }
+}
+
+void ViewConfigureFieldsPage::initGUI()
+{
+ //US change the orientation dependent on the following flag
+ // right the flag is set only staticly.
+ // 0 = 640x480 ; 1 = 240x320
+ bool orientation = 1;
+
+
+ setCaption( i18n("Select Fields to Display") );
+
+ QGridLayout *gl = 0;
+
+ if (orientation == 0)
+ gl = new QGridLayout( this , 6, 4, 0, KDialog::spacingHint() );
+ else
+ gl = new QGridLayout( this , 4, 6, 0, KDialog::spacingHint() );
+
+ #ifndef KAB_EMBEDDED
+ mCategoryCombo = new KComboBox( false, this );
+ #else //KAB_EMBEDDED
+ mCategoryCombo = new QComboBox( false, this );
+ #endif //KAB_EMBEDDED
+
+ mCategoryCombo->insertItem( KABC::Field::categoryLabel( KABC::Field::All ) );
+ mCategoryCombo->insertItem( KABC::Field::categoryLabel( KABC::Field::Frequent ) );
+ mCategoryCombo->insertItem( KABC::Field::categoryLabel( KABC::Field::Address ) );
+ mCategoryCombo->insertItem( KABC::Field::categoryLabel( KABC::Field::Email ) );
+ mCategoryCombo->insertItem( KABC::Field::categoryLabel( KABC::Field::Personal ) );
+ mCategoryCombo->insertItem( KABC::Field::categoryLabel( KABC::Field::Organization ) );
+ mCategoryCombo->insertItem( KABC::Field::categoryLabel( KABC::Field::CustomCategory ) );
+ connect( mCategoryCombo, SIGNAL( activated(int) ), SLOT( slotShowFields(int) ) );
+ gl->addWidget( mCategoryCombo, 0, 0 );
+
+ QLabel *label = new QLabel( i18n( "&Selected fields:" ), this );
+ if (orientation == 0)
+ gl->addWidget( label, 0, 2 );
+ else
+ gl->addWidget( label, 2, 0 );
+
+
+ mUnSelectedBox = new QListBox( this );
+ mUnSelectedBox->setSelectionMode( QListBox::Extended );
+ mUnSelectedBox->setMinimumHeight( 100 );
+ if (orientation == 0)
+ gl->addWidget( mUnSelectedBox, 1, 0 );
+ else
+ gl->addWidget( mUnSelectedBox, 0, 1 );
+
+ mSelectedBox = new QListBox( this );
+ mSelectedBox->setSelectionMode( QListBox::Extended );
+ label->setBuddy( mSelectedBox );
+ if (orientation == 0)
+ gl->addWidget( mSelectedBox, 1, 2 );
+ else
+ gl->addWidget( mSelectedBox, 2, 1 );
+
+ QBoxLayout *vb1 = 0;
+ if (orientation == 0)
+ vb1 = new QBoxLayout( QBoxLayout::TopToBottom, KDialog::spacingHint() );
+ else
+ vb1 = new QBoxLayout( QBoxLayout::LeftToRight, KDialog::spacingHint() );
+
+ vb1->addStretch();
+
+ mAddButton = new QToolButton( this );
+ if (orientation == 0)
+ mAddButton->setIconSet( SmallIconSet( "1rightarrow" ) );
+ else
+ mAddButton->setIconSet( SmallIconSet( "1downarrow" ) );
+ connect( mAddButton, SIGNAL( clicked() ), SLOT( slotSelect() ) );
+ vb1->addWidget( mAddButton );
+
+ mRemoveButton = new QToolButton( this );
+ if (orientation == 0)
+ mRemoveButton->setIconSet( SmallIconSet( "1leftarrow" ) );
+ else
+ mRemoveButton->setIconSet( SmallIconSet( "1uparrow" ) );
+
+ connect( mRemoveButton, SIGNAL( clicked() ), SLOT( slotUnSelect() ) );
+ vb1->addWidget( mRemoveButton );
+
+ vb1->addStretch();
+ if (orientation == 0)
+ gl->addLayout( vb1, 1, 1 );
+ else
+ gl->addLayout( vb1, 1, 1 );
+
+ QBoxLayout *vb2 = 0;
+ if (orientation == 0)
+ vb2 = new QBoxLayout( QBoxLayout::TopToBottom, KDialog::spacingHint() );
+ else
+ vb2 = new QBoxLayout( QBoxLayout::LeftToRight, KDialog::spacingHint() );
+
+ vb2->addStretch();
+
+ mUpButton = new QToolButton( this );
+ mUpButton->setIconSet( SmallIconSet( "1uparrow" ) );
+ connect( mUpButton, SIGNAL( clicked() ), SLOT( slotMoveUp() ) );
+ vb2->addWidget( mUpButton );
+
+ mDownButton = new QToolButton( this );
+ mDownButton->setIconSet( SmallIconSet( "1downarrow" ) );
+ connect( mDownButton, SIGNAL( clicked() ), SLOT( slotMoveDown() ) );
+ vb2->addWidget( mDownButton );
+
+ vb2->addStretch();
+ if (orientation == 0)
+ gl->addLayout( vb2, 1, 3 );
+ else
+ gl->addLayout( vb2, 3, 1 );
+
+ QSize sizeHint = mUnSelectedBox->sizeHint();
+
+ // make sure we fill the list with all items, so that we can
+ // get the maxItemWidth we need to not truncate the view
+ slotShowFields( 0 );
+
+ sizeHint = sizeHint.expandedTo( mSelectedBox->sizeHint() );
+ sizeHint.setWidth( mUnSelectedBox->maxItemWidth() );
+ mUnSelectedBox->setMinimumSize( sizeHint );
+ mSelectedBox->setMinimumSize( sizeHint );
+
+ gl->activate();
+
+ connect( mUnSelectedBox, SIGNAL( selectionChanged() ), SLOT( slotButtonsEnabled() ) );
+ connect( mSelectedBox, SIGNAL( selectionChanged() ), SLOT( slotButtonsEnabled() ) );
+ connect( mSelectedBox, SIGNAL( currentChanged( QListBoxItem * ) ), SLOT( slotButtonsEnabled() ) );
+
+ slotButtonsEnabled();
+}
+
+
+#ifndef KAB_EMBEDDED
+#include "viewconfigurefieldspage.moc"
+#endif //KAB_EMBEDDED
diff --git a/kaddressbook/viewconfigurefieldspage.h b/kaddressbook/viewconfigurefieldspage.h
new file mode 100644
index 0000000..b27668c
--- a/dev/null
+++ b/kaddressbook/viewconfigurefieldspage.h
@@ -0,0 +1,81 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef VIEWCONFIGUREFIELDSPAGE_H
+#define VIEWCONFIGUREFIELDSPAGE_H
+
+#include <qwidget.h>
+
+#include <kabc/field.h>
+#include <kabc/addressbook.h>
+
+#ifndef KAB_EMBEDDED
+class KComboBox;
+#else //KAB_EMBEDDED
+class QComboBox;
+#endif //KAB_EMBEDDED
+
+class QListBox;
+class QListBoxItem;
+class QPushButton;
+class QToolButton;
+
+class ViewConfigureFieldsPage : public QWidget
+{
+ Q_OBJECT
+
+ public:
+ ViewConfigureFieldsPage( KABC::AddressBook *ab, QWidget *parent = 0,
+ const char *name = 0 );
+
+ void restoreSettings( KConfig* );
+ void saveSettings( KConfig* );
+
+ public slots:
+ void slotSelect();
+ void slotUnSelect();
+ void slotMoveUp();
+ void slotMoveDown();
+
+ void slotShowFields( int );
+ void slotButtonsEnabled();
+
+ private:
+ void initGUI();
+
+#ifndef KAB_EMBEDDED
+ KComboBox *mCategoryCombo;
+#else //KAB_EMBEDDED
+ QComboBox *mCategoryCombo;
+#endif //KAB_EMBEDDED
+ QListBox *mSelectedBox;
+ QListBox *mUnSelectedBox;
+ QToolButton *mAddButton;
+ QToolButton *mRemoveButton;
+ QToolButton *mUpButton;
+ QToolButton *mDownButton;
+
+ KABC::AddressBook *mAddressBook;
+};
+
+#endif
diff --git a/kaddressbook/viewconfigurefilterpage.cpp b/kaddressbook/viewconfigurefilterpage.cpp
new file mode 100644
index 0000000..b085a5e
--- a/dev/null
+++ b/kaddressbook/viewconfigurefilterpage.cpp
@@ -0,0 +1,137 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef KAB_EMBEDDED
+#include <kcombobox.h>
+#else //KAB_EMBEDDED
+#include <qcombobox.h>
+#endif //KAB_EMBEDDED
+
+#include <qbuttongroup.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qradiobutton.h>
+
+#include <kconfig.h>
+#include <kdialog.h>
+#include <klocale.h>
+
+#include "filter.h"
+
+#include "viewconfigurefilterpage.h"
+
+ViewConfigureFilterPage::ViewConfigureFilterPage( QWidget *parent,
+ const char *name )
+ : QWidget( parent, name )
+{
+ QBoxLayout *topLayout = new QVBoxLayout( this, 0, KDialog::spacingHint() );
+
+ mFilterGroup = new QButtonGroup();
+ connect( mFilterGroup, SIGNAL( clicked( int ) ), SLOT( buttonClicked( int ) ) );
+
+ QLabel *label = new QLabel( i18n( "The default filter will be activated whenever"
+ " this view is displayed. This feature allows you to configure views that only"
+ " interact with certain types of information based on the filter. Once the view"
+ " is activated, the filter can be changed at anytime." ), this );
+ label->setAlignment( Qt::AlignLeft | Qt::AlignTop | Qt::WordBreak );
+ topLayout->addWidget( label );
+
+ QWidget *spacer = new QWidget( this );
+ spacer->setMinimumHeight( 5 );
+ topLayout->addWidget( spacer );
+
+ QRadioButton *button = new QRadioButton( i18n( "No default filter" ), this );
+ mFilterGroup->insert( button );
+ topLayout->addWidget( button );
+
+ button = new QRadioButton( i18n( "Use last active filter" ), this );
+ mFilterGroup->insert( button );
+ topLayout->addWidget( button );
+
+ QBoxLayout *comboLayout = new QHBoxLayout();
+ topLayout->addLayout( comboLayout );
+ button = new QRadioButton( i18n( "Use filter:" ), this );
+ mFilterGroup->insert( button );
+ comboLayout->addWidget( button );
+
+#ifndef KAB_EMBEDDED
+ mFilterCombo = new KComboBox( this );
+#else //KAB_EMBEDDED
+ mFilterCombo = new QComboBox( this );
+#endif //KAB_EMBEDDED
+
+ comboLayout->addWidget( mFilterCombo );
+}
+
+ViewConfigureFilterPage::~ViewConfigureFilterPage()
+{
+ delete mFilterGroup;
+}
+
+void ViewConfigureFilterPage::restoreSettings( KConfig *config )
+{
+ mFilterCombo->clear();
+
+//US I had to adjust the whole method in order to work with QComboBoxes
+// in case of the Platformindependent version
+ QString defaultfiltername = config->readEntry( "DefaultFilterName" );
+
+ int id = config->readNumEntry( "DefaultFilterType", 1 );
+ mFilterGroup->setButton( id );
+ buttonClicked( id );
+
+ // Load the filter combo
+ Filter::List list = Filter::restore( config, "Filter" );
+ Filter::List::Iterator it;
+ for ( it = list.begin(); it != list.end(); ++it )
+ {
+ mFilterCombo->insertItem( (*it).name() );
+
+ if ( id == 2 && (*it).name() == defaultfiltername) // has default filter
+ {
+ mFilterCombo->insertItem( (*it).name(), 0);
+ }
+ else
+ {
+ mFilterCombo->insertItem( (*it).name() );
+ }
+
+ }
+
+
+}
+
+void ViewConfigureFilterPage::saveSettings( KConfig *config )
+{
+ config->writeEntry( "DefaultFilterName", mFilterCombo->currentText() );
+ config->writeEntry( "DefaultFilterType", mFilterGroup->id( mFilterGroup->selected() ) );
+}
+
+void ViewConfigureFilterPage::buttonClicked( int id )
+{
+ mFilterCombo->setEnabled( id == 2 );
+}
+
+#ifndef KAB_EMBEDDED
+#include "viewconfigurefilterpage.moc"
+#endif //KAB_EMBEDDED
diff --git a/kaddressbook/viewconfigurefilterpage.h b/kaddressbook/viewconfigurefilterpage.h
new file mode 100644
index 0000000..3be9564
--- a/dev/null
+++ b/kaddressbook/viewconfigurefilterpage.h
@@ -0,0 +1,63 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef VIEWCONFIGUREFILTERPAGE
+#define VIEWCONFIGUREFILTERPAGE
+
+#include <qwidget.h>
+
+class QButtonGroup;
+
+#ifndef KAB_EMBEDDED
+class KComboBox;
+#else //KAB_EMBEDDED
+class QComboBox;
+#endif //KAB_EMBEDDED
+
+class KConfig;
+
+class ViewConfigureFilterPage : public QWidget
+{
+ Q_OBJECT
+
+ public:
+ ViewConfigureFilterPage( QWidget *parent, const char *name = 0 );
+ ~ViewConfigureFilterPage();
+
+ void restoreSettings( KConfig* );
+ void saveSettings( KConfig* );
+
+ protected slots:
+ void buttonClicked( int id );
+
+ private:
+#ifndef KAB_EMBEDDED
+ KComboBox *mFilterCombo;
+#else //KAB_EMBEDDED
+ QComboBox *mFilterCombo;
+#endif //KAB_EMBEDDED
+
+ QButtonGroup *mFilterGroup;
+};
+
+#endif
diff --git a/kaddressbook/viewconfigurewidget.cpp b/kaddressbook/viewconfigurewidget.cpp
new file mode 100644
index 0000000..666e188
--- a/dev/null
+++ b/kaddressbook/viewconfigurewidget.cpp
@@ -0,0 +1,159 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+
+#ifndef KAB_EMBEDDED
+
+#include <qvbox.h>
+
+#include <kapplication.h>
+#include <kconfig.h>
+#include <kdebug.h>
+#include <kiconloader.h>
+
+#include "viewmanager.h"
+
+#endif //KAB_EMBEDDED
+
+
+#include <qlayout.h>
+
+#include <kjanuswidget.h>
+#include <kglobal.h>
+#include <klocale.h>
+
+#include "viewconfigurewidget.h"
+#include "viewconfigurefieldspage.h"
+#include "viewconfigurefilterpage.h"
+
+ViewConfigureWidget::ViewConfigureWidget( KABC::AddressBook *ab, QWidget *parent,
+ const char *name )
+ : ConfigureWidget( ab, parent, name )
+{
+ QVBoxLayout *topLayout = new QVBoxLayout( this );
+
+ mMainWidget = new KJanusWidget( this, "JanusWidget", KJanusWidget::Tabbed );
+
+ topLayout->addWidget( mMainWidget );
+
+ // Add the first page, the attributes
+ QVBox *page = addPage( i18n( "Fields" ), QString::null,
+ KGlobal::iconLoader()->loadIcon( "view_detailed",
+ KIcon::Panel, 16 ) );
+
+
+ // Add the select fields page
+ mFieldsPage = new ViewConfigureFieldsPage( addressBook(), (QWidget*)page );
+
+//US mFieldsPage->setMinimumSize(300,300);
+
+ // Add the second page, the filter selection
+ page = addPage( i18n( "Default Filter" ), QString::null,
+ KGlobal::iconLoader()->loadIcon( "filter",
+ KIcon::Panel, 16 ) );
+
+ mFilterPage = new ViewConfigureFilterPage( (QWidget*)page );
+ //qDebug("+++++ViewConfigureWidget::ViewConfigureWidget ");
+}
+
+ViewConfigureWidget::~ViewConfigureWidget()
+{
+ //qDebug("-----ViewConfigureWidget::~ViewConfigureWidget() ");
+}
+
+void ViewConfigureWidget::restoreSettings( KConfig *config )
+{
+ mFieldsPage->restoreSettings( config );
+ mFilterPage->restoreSettings( config );
+}
+
+void ViewConfigureWidget::saveSettings( KConfig *config )
+{
+ mFieldsPage->saveSettings( config );
+ mFilterPage->saveSettings( config );
+}
+
+QVBox *ViewConfigureWidget::addPage( const QString &item, const QString &header,
+ const QPixmap &pixmap )
+{
+ return mMainWidget->addVBoxPage( item, header, pixmap );
+}
+
+#include <qframe.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <stdlib.h>
+
+ViewConfigureDialog::ViewConfigureDialog( ViewConfigureWidget *wdg, const QString &viewName,
+ QWidget *parent, const char *name )
+ : KDialogBase( Swallow, i18n( "Modify View: " ) + viewName, Help | Ok | Cancel,
+ Ok, parent, name, true, true ), mConfigWidget( wdg )
+{
+//US, I have to change the way, how to connect the ViewConfigureWidget. It looks
+// like it has changed.
+ //QFrame *topFrame = plainPage();
+ if ( mConfigWidget ) {
+ mConfigWidget->reparent(this, QPoint(0,0), true);
+ // QVBoxLayout * layout = new QVBoxLayout( this );
+ //layout->addWidget(mConfigWidget );
+ //mConfigWidget->reparent(topFrame, QPoint(1,1), true);
+
+ setMainWidget( mConfigWidget );
+ }
+
+}
+
+ViewConfigureDialog::~ViewConfigureDialog()
+{
+}
+void ViewConfigureDialog::setWidget( ViewConfigureWidget *wdg )
+{
+ mConfigWidget = wdg ;
+ setMainWidget( mConfigWidget );
+
+}
+
+void ViewConfigureDialog::restoreSettings( KConfig *config )
+{
+ mConfigWidget->restoreSettings( config );
+}
+
+void ViewConfigureDialog::saveSettings( KConfig *config )
+{
+ mConfigWidget->saveSettings( config );
+}
+
+void ViewConfigureDialog::slotHelp()
+{
+#ifndef KAB_EMBEDDED
+ kapp->invokeHelp( "using-views" );
+#else //KAB_EMBEDDED
+ qDebug("ViewConfigureDialog::slotHelp not yet implemented");
+#endif //KAB_EMBEDDED
+}
+
+#ifndef KAB_EMBEDDED
+#include "viewconfigurewidget.moc"
+#endif //KAB_EMBEDDED
+
+
diff --git a/kaddressbook/viewconfigurewidget.h b/kaddressbook/viewconfigurewidget.h
new file mode 100644
index 0000000..0c2b77c
--- a/dev/null
+++ b/kaddressbook/viewconfigurewidget.h
@@ -0,0 +1,106 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
+
+ This program is free software; you can rremovePageedistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef VIEWCONFIGUREWIDGET_H
+#define VIEWCONFIGUREWIDGET_H
+
+
+
+#include "configurewidget.h"
+
+class QVBox;
+
+#include <kdialogbase.h>
+#include <qpixmap.h>
+
+class KJanusWidget;
+class QString;
+class ViewConfigureFieldsPage;
+class ViewConfigureFilterPage;
+class ViewConfigureDialog;
+/**
+ This widget is the base class for all view configuration widgets. The
+ author of a view may wish to inherit from this widget and add config pages
+ that add custom config options. The default implementation of this widget
+ is to show a page with the select fields widget. For simple views this may
+ be sufficient.
+*/
+class ViewConfigureWidget : public ConfigureWidget
+{
+ Q_OBJECT
+
+ public:
+ ViewConfigureWidget( KABC::AddressBook *ab, QWidget *parent, const char *name = 0 );
+ virtual ~ViewConfigureWidget();
+
+ /**
+ Reads the configuration from the config object and sets the values
+ in the GUI. If this method is overloaded, be sure to call the base
+ class's method.
+
+ Do not change the group of the config object in this method.
+ */
+ virtual void restoreSettings( KConfig *config );
+
+ /**
+ Writes the configuration from the GUI to the config object. If this
+ method is overloaded, be sure to call the base class's method.
+
+ Do not change the group of the config object in this method.
+ */
+ virtual void saveSettings( KConfig *config );
+
+
+ /**
+ Use this method to add new pages to the widget.
+ */
+ QVBox *addPage( const QString &item, const QString &header = QString::null,
+ const QPixmap &pixmap = QPixmap() );
+
+ private:
+ KJanusWidget *mMainWidget;
+
+ ViewConfigureFieldsPage *mFieldsPage;
+ ViewConfigureFilterPage *mFilterPage;
+};
+
+class ViewConfigureDialog : public KDialogBase
+{
+ Q_OBJECT
+
+ public:
+ ViewConfigureDialog( ViewConfigureWidget *wdg, const QString &viewName,
+ QWidget *parent, const char *name = 0 );
+ ~ViewConfigureDialog();
+
+ void restoreSettings( KConfig* );
+ void saveSettings( KConfig* );
+ void setWidget( ViewConfigureWidget *wdg );
+ protected slots:
+ void slotHelp();
+
+ private:
+ ViewConfigureWidget *mConfigWidget;
+};
+
+#endif
diff --git a/kaddressbook/viewmanager.cpp b/kaddressbook/viewmanager.cpp
new file mode 100644
index 0000000..e8c5b45
--- a/dev/null
+++ b/kaddressbook/viewmanager.cpp
@@ -0,0 +1,685 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+/*
+Enhanced Version of the file for platform independent KDE tools.
+Copyright (c) 2004 Ulf Schenk
+
+$Id$
+*/
+
+
+#ifndef KAB_EMBEDDED
+#include <libkdepim/kvcarddrag.h>
+#include <kabc/vcardconverter.h>
+#include <kconfig.h>
+#include <kdeversion.h>
+#include <kiconloader.h>
+#include <klocale.h>
+#include <kmessagebox.h>
+#include <kmultipledrag.h>
+#include <ktrader.h>
+#include <kurldrag.h>
+
+#include "addresseeutil.h"
+#else //KAB_EMBEDDED
+#include "views/kaddressbookiconview.h"
+#include "views/kaddressbooktableview.h"
+#include "views/kaddressbookcardview.h"
+#include "kaddressbookview.h"
+
+#include <qaction.h>
+#include <qmessagebox.h>
+#include <qpopupmenu.h>
+#include <kconfigbase.h>
+
+#endif //KAB_EMBEDDED
+
+
+#include <kdebug.h>
+#include <kactionclasses.h>
+
+#include <qlayout.h>
+#include <qwidgetstack.h>
+
+#include <kabc/addressbook.h>
+#include "filtereditdialog.h"
+#include "addviewdialog.h"
+#include "kabcore.h"
+#include "kabprefs.h"
+#include "viewmanager.h"
+
+ViewManager::ViewManager( KABCore *core, QWidget *parent, const char *name )
+ : QWidget( parent, name ), mCore( core ), mActiveView( 0 )
+{
+ initGUI();
+ initActions();
+
+ mViewDict.setAutoDelete( true );
+
+ createViewFactories();
+}
+
+ViewManager::~ViewManager()
+{
+ unloadViews();
+ mViewFactoryDict.clear();
+}
+
+void ViewManager::restoreSettings()
+{
+ mViewNameList = KABPrefs::instance()->mViewNames;
+ QString activeViewName = KABPrefs::instance()->mCurrentView;
+
+ mActionSelectView->setItems( mViewNameList );
+
+ // Filter
+ mFilterList = Filter::restore( mCore->config(), "Filter" );
+ mActionSelectFilter->setItems( filterNames() );
+ mActionSelectFilter->setCurrentItem( KABPrefs::instance()->mCurrentFilter );
+
+ // Tell the views to reread their config, since they may have
+ // been modified by global settings
+ QString _oldgroup = mCore->config()->group();
+
+ QDictIterator<KAddressBookView> it( mViewDict );
+ for ( it.toFirst(); it.current(); ++it ) {
+ KConfigGroupSaver saver( mCore->config(), it.currentKey() );
+ it.current()->readConfig( mCore->config() );
+ }
+ setActiveView( activeViewName );
+
+ mActionDeleteView->setEnabled( mViewNameList.count() > 1 );
+}
+
+void ViewManager::saveSettings()
+{
+ QString _oldgroup = mCore->config()->group();
+
+ QDictIterator<KAddressBookView> it( mViewDict );
+ for ( it.toFirst(); it.current(); ++it ) {
+ KConfigGroupSaver saver( mCore->config(), it.currentKey() );
+#ifdef DESKTOP_VERSION
+ (*it)->writeConfig( mCore->config() );
+#else
+ (*it).writeConfig( mCore->config() );
+#endif
+ }
+
+ Filter::save( mCore->config(), "Filter", mFilterList );
+ KABPrefs::instance()->mCurrentFilter = mActionSelectFilter->currentItem();
+
+ // write the view name list
+ KABPrefs::instance()->mViewNames = mViewNameList;
+ KABPrefs::instance()->mCurrentView = mActiveView->caption();
+
+}
+
+QStringList ViewManager::selectedUids() const
+{
+ if ( mActiveView )
+ return mActiveView->selectedUids();
+ else
+ return QStringList();
+}
+
+QStringList ViewManager::selectedEmails() const
+{
+ if ( mActiveView )
+ return mActiveView->selectedEmails();
+ else
+ return QStringList();
+}
+
+KABC::Addressee::List ViewManager::selectedAddressees() const
+{
+ KABC::Addressee::List list;
+ if ( mActiveView ) {
+ QStringList uids = mActiveView->selectedUids();
+ QStringList::Iterator it;
+ for ( it = uids.begin(); it != uids.end(); ++it ) {
+ KABC::Addressee addr = mCore->addressBook()->findByUid( *it );
+ if ( !addr.isEmpty() )
+ list.append( addr );
+ }
+ }
+
+ return list;
+}
+//US added another method with no parameter, since my moc compiler does not support default parameters.
+void ViewManager::setSelected()
+{
+ setSelected( QString::null, true );
+}
+
+void ViewManager::setSelected( const QString &uid, bool selected )
+{
+ if ( mActiveView )
+ mActiveView->setSelected( uid, selected );
+}
+
+void ViewManager::unloadViews()
+{
+ mViewDict.clear();
+ mActiveView = 0;
+}
+
+void ViewManager::setActiveView( const QString &name )
+{
+ KAddressBookView *view = 0;
+
+ // Check that this isn't the same as the current active view
+ if ( mActiveView && ( mActiveView->caption() == name ) )
+ return;
+
+ // At this point we know the view that should be active is not
+ // currently active. We will try to find the new on in the list. If
+ // we can't find it, it means it hasn't been instantiated, so we will
+ // create it on demand.
+
+ view = mViewDict.find( name );
+
+ // Check if we found the view. If we didn't, then we need to create it
+ if ( view == 0 ) {
+ KConfig *config = mCore->config();
+
+ KConfigGroupSaver saver( config, name );
+
+ QString type = config->readEntry( "Type", "Table" );
+
+ kdDebug(5720) << "ViewManager::setActiveView: creating view - " << name << endl;
+
+ ViewFactory *factory = mViewFactoryDict.find( type );
+ if ( factory )
+ view = factory->view( mCore->addressBook(), mViewWidgetStack );
+
+ if ( view ) {
+ view->setCaption( name );
+ mViewDict.insert( name, view );
+//US my version needs an int as second parameter to addWidget
+ mViewWidgetStack->addWidget( view, -1 );
+ view->readConfig( config );
+
+ // The manager just relays the signals
+ connect( view, SIGNAL( selected( const QString& ) ),
+ SIGNAL( selected( const QString & ) ) );
+ connect( view, SIGNAL( executed( const QString& ) ),
+ SIGNAL( executed( const QString& ) ) );
+
+ connect( view, SIGNAL( deleteRequest( ) ),
+ SIGNAL( deleteRequest( ) ) );
+
+ connect( view, SIGNAL( modified() ), SIGNAL( modified() ) );
+ connect( view, SIGNAL( dropped( QDropEvent* ) ),
+ SLOT( dropped( QDropEvent* ) ) );
+ connect( view, SIGNAL( startDrag() ), SLOT( startDrag() ) );
+ }
+ }
+
+ // If we found or created the view, raise it and refresh it
+ if ( view ) {
+ mActiveView = view;
+ mViewWidgetStack->raiseWidget( view );
+ // Set the proper filter in the view. By setting the combo
+ // box, the activated slot will be called, which will push
+ // the filter to the view and refresh it.
+
+ if ( view->defaultFilterType() == KAddressBookView::None ) {
+
+ mActionSelectFilter->setCurrentItem( 0 );
+ setActiveFilter( 0 );
+ } else if ( view->defaultFilterType() == KAddressBookView::Active ) {
+ setActiveFilter( mActionSelectFilter->currentItem() );
+ } else {
+ uint pos = filterPosition( view->defaultFilterName() );
+ mActionSelectFilter->setCurrentItem( pos );
+ setActiveFilter( pos );
+ }
+//US qDebug("ViewManager::setActiveView 6" );
+
+ // Update the inc search widget to show the fields in the new active
+ // view.
+ mCore->setSearchFields( mActiveView->fields() );
+
+ mActiveView->refresh();
+
+ }
+ else
+ {
+ qDebug("ViewManager::setActiveView: unable to find view" );
+ kdDebug(5720) << "ViewManager::setActiveView: unable to find view\n";
+ }
+}
+
+//US added another method with no parameter, since my moc compiler does not support default parameters.
+void ViewManager::refreshView()
+{
+ refreshView( QString::null );
+}
+
+void ViewManager::refreshView( const QString &uid )
+{
+ if ( mActiveView )
+ mActiveView->refresh( uid );
+}
+
+void ViewManager::editView()
+{
+ if ( !mActiveView )
+ return;
+
+ ViewFactory *factory = mViewFactoryDict.find( mActiveView->type() );
+ ViewConfigureWidget *wdg = 0;
+ ViewConfigureDialog* dlg = 0;
+ if ( factory ) {
+ // Save the filters so the dialog has the latest set
+ Filter::save( mCore->config(), "Filter", mFilterList );
+ dlg = new ViewConfigureDialog( 0, mActiveView->caption(), this, "conf_dlg" );
+ wdg = factory->configureWidget( mCore->addressBook(), dlg,"conf_wid" );
+ } else {
+ qDebug("ViewManager::editView()::cannot find viewfactory ");
+ return;
+ }
+ if ( wdg ) {
+ dlg->setWidget( wdg );
+
+#ifndef DESKTOP_VERSION
+ //dlg.setMaximumSize( 640, 480 );
+ //dlg->setGeometry( 40,40, 400, 300);
+ dlg->showMaximized();
+#endif
+
+ KConfigGroupSaver saver( mCore->config(), mActiveView->caption() );
+
+ dlg->restoreSettings( mCore->config() );
+
+ if ( dlg->exec() ) {
+ dlg->saveSettings( mCore->config() );
+ mActiveView->readConfig( mCore->config() );
+
+ // Set the proper filter in the view. By setting the combo
+ // box, the activated slot will be called, which will push
+ // the filter to the view and refresh it.
+ if ( mActiveView->defaultFilterType() == KAddressBookView::None ) {
+ mActionSelectFilter->setCurrentItem( 0 );
+ setActiveFilter( 0 );
+ } else if ( mActiveView->defaultFilterType() == KAddressBookView::Active ) {
+ setActiveFilter( mActionSelectFilter->currentItem() );
+ } else {
+ uint pos = filterPosition( mActiveView->defaultFilterName() );
+ mActionSelectFilter->setCurrentItem( pos );
+ setActiveFilter( pos );
+ }
+ mCore->setSearchFields( mActiveView->fields() );
+ mActiveView->refresh();
+ }
+
+ }
+ delete dlg;
+}
+
+void ViewManager::deleteView()
+{
+ QString text = i18n( "<qt>Are you sure that you want to delete the view <b>%1</b>?</qt>" )
+ .arg( mActiveView->caption() );
+ QString caption = i18n( "Confirm Delete" );
+
+
+ if (QMessageBox::information( this, caption,
+ text,
+ i18n("Yes!"), i18n("No"), 0, 0 ) == 0)
+ {
+ mViewNameList.remove( mActiveView->caption() );
+
+ // remove the view from the config file
+ KConfig *config = mCore->config();
+ config->deleteGroup( mActiveView->caption() );
+
+ mViewDict.remove( mActiveView->caption() );
+ mActiveView = 0;
+
+ // we are in an invalid state now, but that should be fixed after
+ // we emit the signal
+ mActionSelectView->setItems( mViewNameList );
+ if ( mViewNameList.count() > 0 ) {
+ mActionSelectView->setCurrentItem( 0 );
+ setActiveView( mViewNameList[ 0 ] );
+ }
+ mActionDeleteView->setEnabled( mViewNameList.count() > 1 );
+ }
+}
+
+void ViewManager::addView()
+{
+ AddViewDialog dialog( &mViewFactoryDict, this );
+
+ if ( dialog.exec() ) {
+ QString newName = dialog.viewName();
+ QString type = dialog.viewType();
+
+ // Check for name conflicts
+ bool firstConflict = true;
+ int numTries = 1;
+ while ( mViewNameList.contains( newName ) > 0 ) {
+ if ( !firstConflict ) {
+ newName = newName.left( newName.length() - 4 );
+ firstConflict = false;
+ }
+
+ newName = QString( "%1 <%2>" ).arg( newName ).arg( numTries );
+ numTries++;
+ }
+
+ // Add the new one to the list
+ mViewNameList.append( newName );
+
+ // write the view to the config file,
+ KConfig *config = mCore->config();
+
+ config->deleteGroup( newName );
+
+ KConfigGroupSaver saver( config, newName );
+
+ config->writeEntry( "Type", type );
+
+ // try to set the active view
+ mActionSelectView->setItems( mViewNameList );
+ mActionSelectView->setCurrentItem( mViewNameList.findIndex( newName ) );
+ setActiveView( newName );
+
+ editView();
+
+ mActionDeleteView->setEnabled( mViewNameList.count() > 1 );
+ }
+}
+
+void ViewManager::createViewFactories()
+{
+#ifndef KAB_EMBEDDED
+ KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/View" );
+ KTrader::OfferList::ConstIterator it;
+ for ( it = plugins.begin(); it != plugins.end(); ++it ) {
+ if ( !(*it)->hasServiceType( "KAddressBook/View" ) )
+ continue;
+
+ KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() );
+
+ if ( !factory ) {
+ kdDebug(5720) << "ViewManager::createViewFactories(): Factory creation failed" << endl;
+ continue;
+ }
+
+ ViewFactory *viewFactory = static_cast<ViewFactory*>( factory );
+
+ if ( !viewFactory ) {
+ kdDebug(5720) << "ViewManager::createViewFactories(): Cast failed" << endl;
+ continue;
+ }
+
+ mViewFactoryDict.insert( viewFactory->type(), viewFactory );
+ }
+
+#else //KAB_EMBEDDED
+ ViewFactory* viewFactory = new IconViewFactory();
+ mViewFactoryDict.insert( viewFactory->type(), viewFactory );
+// qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1());
+
+ viewFactory = new TableViewFactory();
+ mViewFactoryDict.insert( viewFactory->type(), viewFactory );
+// qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1());
+
+ viewFactory = new CardViewFactory();
+ mViewFactoryDict.insert( viewFactory->type(), viewFactory );
+// qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1());
+
+#endif //KAB_EMBEDDED
+
+}
+
+void ViewManager::dropped( QDropEvent *e )
+{
+ kdDebug(5720) << "ViewManager::dropped: got a drop event" << endl;
+
+#ifndef KAB_EMBEDDED
+
+ QString clipText, vcards;
+ KURL::List urls;
+
+ if ( KURLDrag::decode( e, urls) ) {
+ KURL::List::Iterator it = urls.begin();
+ int c = urls.count();
+ if ( c > 1 ) {
+ QString questionString = i18n( "Import one contact into your addressbook?", "Import %n contacts into your addressbook?", c );
+ if ( KMessageBox::questionYesNo( this, questionString, i18n( "Import Contacts?" ) ) == KMessageBox::Yes ) {
+ for ( ; it != urls.end(); ++it )
+ emit urlDropped( *it );
+ }
+ } else if ( c == 1 )
+ emit urlDropped( *it );
+ } else if ( KVCardDrag::decode( e, vcards ) ) {
+ KABC::Addressee addr;
+ KABC::VCardConverter converter;
+ QStringList list = QStringList::split( "\r\n\r\n", vcards );
+ QStringList::Iterator it;
+ for ( it = list.begin(); it != list.end(); ++it ) {
+ if ( converter.vCardToAddressee( (*it).stripWhiteSpace(), addr ) ) {
+ KABC::Addressee a = mCore->addressBook()->findByUid( addr.uid() );
+ if ( a.isEmpty() ) {
+ mCore->addressBook()->insertAddressee( addr );
+ emit modified();
+ }
+ }
+ }
+
+ mActiveView->refresh();
+ }
+#else //KAB_EMBEDDED
+qDebug("ViewManager::dropped() has to be changed!!" );
+#endif //KAB_EMBEDDED
+
+}
+
+void ViewManager::startDrag()
+{
+ kdDebug(5720) << "ViewManager::startDrag: starting to drag" << endl;
+
+#ifndef KAB_EMBEDDED
+
+ // Get the list of all the selected addressees
+ KABC::Addressee::List addrList;
+ QStringList uidList = selectedUids();
+ QStringList::Iterator iter;
+ for ( iter = uidList.begin(); iter != uidList.end(); ++iter )
+ addrList.append( mCore->addressBook()->findByUid( *iter ) );
+
+ KMultipleDrag *drag = new KMultipleDrag( this );
+ drag->addDragObject( new QTextDrag( AddresseeUtil::addresseesToClipboard(addrList), this ) );
+ KABC::Addressee::List::Iterator it;
+ QStringList vcards;
+ for ( it = addrList.begin(); it != addrList.end(); ++it ) {
+ QString vcard = QString::null;
+ KABC::VCardConverter converter;
+ if ( converter.addresseeToVCard( *it, vcard ) )
+ vcards.append( vcard );
+ }
+ drag->addDragObject( new KVCardDrag( vcards.join( "\r\n" ), this ) );
+
+ drag->setPixmap( KGlobal::iconLoader()->loadIcon( "vcard", KIcon::Desktop ) );
+ drag->dragCopy();
+
+#else //KAB_EMBEDDED
+qDebug("ViewManager::startDrag() has to be changed!!" );
+#endif //KAB_EMBEDDED
+
+}
+
+void ViewManager::setActiveFilter( int index )
+{
+ Filter currentFilter;
+
+ if ( ( index - 1 ) < 0 )
+ currentFilter = Filter();
+ else
+ currentFilter = mFilterList[ index - 1 ];
+
+ // Check if we have a view. Since the filter combo is created before
+ // the view, this slot could be called before there is a valid view.
+ if ( mActiveView ) {
+ mActiveView->setFilter( currentFilter );
+ mActiveView->refresh();
+ emit selected( QString::null );
+ }
+}
+
+void ViewManager::configureFilters()
+{
+ FilterDialog dlg( this );
+
+ dlg.setFilters( mFilterList );
+
+ if ( dlg.exec() )
+ mFilterList = dlg.filters();
+
+ uint pos = mActionSelectFilter->currentItem();
+ mActionSelectFilter->setItems( filterNames() );
+ mActionSelectFilter->setCurrentItem( pos );
+ setActiveFilter( pos );
+}
+
+QStringList ViewManager::filterNames() const
+{
+ QStringList names( i18n( "No Filter" ) );
+
+ Filter::List::ConstIterator it;
+ for ( it = mFilterList.begin(); it != mFilterList.end(); ++it )
+ names.append( (*it).name() );
+
+ return names;
+}
+
+int ViewManager::filterPosition( const QString &name ) const
+{
+ int pos = 0;
+
+ Filter::List::ConstIterator it;
+ for ( it = mFilterList.begin(); it != mFilterList.end(); ++it, ++pos )
+ if ( name == (*it).name() )
+ return pos + 1;
+
+ return 0;
+}
+
+void ViewManager::initActions()
+{
+//US <ActionList name="view_loadedviews"/>
+//US <Separator/>
+
+#ifdef KAB_EMBEDDED
+ QPopupMenu *viewmenu = (QPopupMenu*)mCore->getViewMenu();
+ QPopupMenu *settingsmenu = (QPopupMenu*)mCore->getSettingsMenu();
+ QPopupMenu *filtermenu = (QPopupMenu*)mCore->getFilterMenu();
+#endif //KAB_EMBEDDED
+
+ mActionSelectView = new KSelectAction( i18n( "Select View" ), 0, mCore->actionCollection(), "select_view" );
+#if KDE_VERSION >= 309
+ mActionSelectView->setMenuAccelsEnabled( false );
+#endif
+ connect( mActionSelectView, SIGNAL( activated( const QString& ) ),
+ SLOT( setActiveView( const QString& ) ) );
+
+
+#ifdef KAB_EMBEDDED
+ mActionSelectView->plug(viewmenu);
+ viewmenu->insertSeparator();
+#endif //KAB_EMBEDDED
+
+ KAction *action;
+
+ action = new KAction( i18n( "Modify View..." ), "configure", 0, this,
+ SLOT( editView() ), mCore->actionCollection(), "view_modify" );
+#ifndef KAB_EMBEDDED
+ action->setWhatsThis( i18n( "By pressing this button a dialog opens that allows you to modify the view of the addressbook. There you can add or remove fields that you want to be shown or hidden in the addressbook like the name for example." ) );
+#else //KAB_EMBEDDED
+ action->plug(viewmenu);
+#endif //KAB_EMBEDDED
+
+ action = new KAction( i18n( "Add View..." ), "window_new", 0, this,
+ SLOT( addView() ), mCore->actionCollection(), "view_add" );
+#ifndef KAB_EMBEDDED
+ action->setWhatsThis( i18n( "You can add a new view by choosing one of the dialog that appears after pressing the button. You have to give the view a name, so that you can distinguish between the different views." ) );
+#else //KAB_EMBEDDED
+ action->plug(viewmenu);
+#endif //KAB_EMBEDDED
+
+ mActionDeleteView = new KAction( i18n( "Delete View" ), "view_remove", 0,
+ this, SLOT( deleteView() ),
+ mCore->actionCollection(), "view_delete" );
+#ifndef KAB_EMBEDDED
+ mActionDeleteView->setWhatsThis( i18n( "By pressing this button you can delete the actual view, which you have added before." ) );
+#else //KAB_EMBEDDED
+ mActionDeleteView->plug(viewmenu);
+ viewmenu->insertSeparator();
+#endif //KAB_EMBEDDED
+
+#ifndef KAB_EMBEDDED
+ action = new KAction( i18n( "Refresh View" ), "reload", 0, this,
+ SLOT( refreshView(const QString &) ), mCore->actionCollection(),
+ "view_refresh" );
+ action->setWhatsThis( i18n( "The view will be refreshed by pressing this button." ) );
+#else //KAB_EMBEDDED
+ action = new KAction( i18n( "Refresh View" ), "reload", 0, this,
+ SLOT( refreshView()), mCore->actionCollection(),
+ "view_refresh" );
+ action->plug(viewmenu);
+ viewmenu->insertSeparator();
+#endif //KAB_EMBEDDED
+
+ action = new KAction( i18n( "Edit &Filters..." ), "filter", 0, this,
+ SLOT( configureFilters() ), mCore->actionCollection(),
+ "options_edit_filters" );
+
+ mActionSelectFilter = new KSelectAction( i18n( "Select Filter" ), "filter", mCore->actionCollection(), "select_filter" );
+
+#if KDE_VERSION >= 309
+ mActionSelectFilter->setMenuAccelsEnabled( false );
+#endif
+ connect( mActionSelectFilter, SIGNAL( activated( int ) ),
+ SLOT( setActiveFilter( int ) ) );
+
+#ifdef KAB_EMBEDDED
+ action->plug(settingsmenu);
+ mActionSelectFilter->plug(viewmenu);
+#endif //KAB_EMBEDDED
+
+}
+
+void ViewManager::initGUI()
+{
+ QHBoxLayout *layout = new QHBoxLayout( this, 0, 0 );
+ mViewWidgetStack = new QWidgetStack( this );
+ layout->addWidget( mViewWidgetStack );
+}
+
+#ifndef KAB_EMBEDDED
+#include "viewmanager.moc"
+#endif //KAB_EMBEDDED
diff --git a/kaddressbook/viewmanager.h b/kaddressbook/viewmanager.h
new file mode 100644
index 0000000..a18e87d
--- a/dev/null
+++ b/kaddressbook/viewmanager.h
@@ -0,0 +1,152 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef VIEWMANAGER_H
+#define VIEWMANAGER_H
+
+#include <qwidget.h>
+#include <qstringlist.h>
+#include <kaddressbookview.h>
+#include <qdict.h>
+
+class KAction;
+class KSelectAction;
+
+class KABCore;
+class QWidgetStack;
+class QDropEvent;
+
+namespace KABC { class AddressBook; }
+
+/**
+ The view manager manages the views and everything related to them. The
+ manager will load the views at startup and display a view when told to
+ make one active.
+
+ The view manager will also create and manage all dialogs directly related to
+ views (ie: AddView, ConfigureView, DeleteView, etc).
+ */
+class ViewManager : public QWidget
+{
+ Q_OBJECT
+ public:
+ ViewManager( KABCore *core, QWidget *parent, const char *name = 0 );
+ ~ViewManager();
+
+ void restoreSettings();
+ void saveSettings();
+
+ void unloadViews();
+ KSelectAction * getFilterAction() { return mActionSelectFilter; }
+
+ QStringList selectedUids() const;
+ QStringList selectedEmails() const;
+ KABC::Addressee::List selectedAddressees() const;
+
+ public slots:
+
+//US void setSelected( const QString &uid = QString::null, bool selected = true );
+ void setSelected( const QString &uid, bool);
+//US added another method with no parameter, since my moc compiler does not support default parameters.
+ void setSelected();
+
+
+
+//US added another method with no parameter, since my moc compiler does not support default parameters.
+ void refreshView();
+ void refreshView( const QString &uid);
+
+ void editView();
+ void deleteView();
+ void addView();
+
+ protected slots:
+ /**
+ Called whenever the user drops something in the active view.
+ This method will try to decode what was dropped, and if it was
+ a valid addressee, add it to the addressbook.
+ */
+ void dropped( QDropEvent* );
+
+ /**
+ Called whenever the user attempts to start a drag in the view.
+ This method will convert all the selected addressees into text (vcard)
+ and create a drag object.
+ */
+ void startDrag();
+
+ signals:
+ /**
+ Emitted whenever the user selects an entry in the view.
+ */
+ void selected( const QString &uid );
+ void deleteRequest( );
+
+ /**
+ Emitted whenever the user activates an entry in the view.
+ */
+ void executed( const QString &uid );
+
+ /**
+ Emitted whenever the address book is modified in some way.
+ */
+ void modified();
+
+ /**
+ Emitted whenever a url is dragged on a view.
+ */
+ void urlDropped( const KURL& );
+
+ private slots:
+ void setActiveView( const QString &name );
+ void setActiveFilter( int index );
+ void configureFilters();
+
+ private:
+ void createViewFactories();
+ QStringList filterNames() const;
+ int filterPosition( const QString &name ) const;
+ QStringList viewNames() const;
+ int viewPosition( const QString &name ) const;
+ void initActions();
+ void initGUI();
+
+ KABCore *mCore;
+
+ Filter mCurrentFilter;
+ Filter::List mFilterList;
+
+ QDict<KAddressBookView> mViewDict;
+ QDict<ViewFactory> mViewFactoryDict;
+ QStringList mViewNameList;
+
+ QWidgetStack *mViewWidgetStack;
+ KAddressBookView *mActiveView;
+
+ KAction *mActionDeleteView;
+ KSelectAction *mActionSelectFilter;
+ KSelectAction *mActionSelectView;
+
+};
+
+#endif
diff --git a/kaddressbook/views/cardview.cpp b/kaddressbook/views/cardview.cpp
new file mode 100644
index 0000000..65f793c
--- a/dev/null
+++ b/kaddressbook/views/cardview.cpp
@@ -0,0 +1,1719 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+//BEGIN Includes
+#include "cardview.h"
+
+#include <limits.h>
+
+#include <qpainter.h>
+#include <qtimer.h>
+#include <qdatetime.h>
+#include <qlabel.h>
+#include <qstyle.h>
+#include <qcursor.h>
+#include <qtooltip.h>
+
+#include <kdebug.h>
+#include <kglobalsettings.h>
+//END includes
+
+#define MIN_ITEM_WIDTH 80
+
+//BEGIN Helpers
+//////////////////////////////////////
+// CardViewTip
+class CardViewTip : public QLabel {
+ public:
+ CardViewTip(QWidget *parent=0, const char *name=0) : QLabel( parent, name )
+ {
+ setPalette( QToolTip::palette() );
+ setFrameStyle( Panel|Plain );
+ setMidLineWidth(0);
+ setIndent(1);
+ }
+
+ ~CardViewTip() {};
+ protected:
+ void leaveEvent( QEvent * )
+ {
+ hide();
+ }
+};
+
+//////////////////////////////////////
+// CardViewItemList
+
+
+//
+// Warning: make sure you use findRef() instead of find() to find an
+// item! Only the pointer value is unique in the list.
+//
+class CardViewItemList : public QPtrList<CardViewItem>
+{
+ protected:
+ virtual int compareItems(QPtrCollection::Item item1,
+ QPtrCollection::Item item2)
+ {
+ CardViewItem *cItem1 = (CardViewItem*)item1;
+ CardViewItem *cItem2 = (CardViewItem*)item2;
+
+ if ( cItem1 == cItem2 )
+ return 0;
+
+ if ((cItem1 == 0) || (cItem2 == 0))
+ return cItem1 ? -1 : 1;
+
+ if (cItem1->caption() < cItem2->caption())
+ return -1;
+
+ else if (cItem1->caption() > cItem2->caption())
+ return 1;
+
+ return 0;
+ }
+
+ private:
+ /*int find( const CardViewItem * )
+ {
+ qDebug("DON'T USE CardViewItemList::find( item )! Use findRef( item )!");
+ }*/
+};
+
+//////////////////////////////////////
+// CardViewSeparator
+class CardViewSeparator
+{
+ friend class CardView;
+
+ public:
+ CardViewSeparator(CardView *view)
+ : mView(view)
+ {
+ mRect = QRect(0, 0, view->separatorWidth(), 0);
+ }
+
+ ~CardViewSeparator() {}
+
+ void paintSeparator(QPainter *p, QColorGroup &cg)
+ {
+ p->fillRect(0, 0, mRect.width(), mRect.height(),
+ cg.brush(QColorGroup::Button));
+ }
+
+ void repaintSeparator()
+ {
+ mView->repaintContents(mRect);
+ }
+
+ private:
+ CardView *mView;
+ QRect mRect;
+};
+
+//END Helpers
+
+//BEGIN Private Data
+
+class CardViewPrivate
+{
+ public:
+ CardViewPrivate()
+ : mSelectionMode( CardView::Multi ),
+ mDrawCardBorder( true ),
+ mDrawFieldLabels( true ),
+ mDrawSeparators( true),
+ mSepWidth( 2 ),
+ mShowEmptyFields( false ),
+ mLayoutDirty( true ),
+ mLastClickOnItem( false ),
+ mItemMargin( 0 ),
+ mItemSpacing( 10 ),
+ mItemWidth( 200 ),
+ mMaxFieldLines( INT_MAX ),
+ mCurrentItem( 0L ),
+ mLastClickPos( QPoint(0, 0) ),
+ mRubberBandAnchor( 0 ),
+ mCompText( QString::null ),
+ mResizeAnchor(0)
+ {};
+
+ CardViewItemList mItemList;
+ QPtrList<CardViewSeparator> mSeparatorList;
+ QFontMetrics *mFm;
+ QFontMetrics *mBFm; // bold font
+ QFont mHeaderFont; // custom header font
+ CardView::SelectionMode mSelectionMode;
+ bool mDrawCardBorder;
+ bool mDrawFieldLabels;
+ bool mDrawSeparators;
+ int mSepWidth;
+ bool mShowEmptyFields;
+ bool mLayoutDirty;
+ bool mLastClickOnItem;
+ uint mItemMargin; // internal margin in items
+ uint mItemSpacing; // spacing between items, column seperators and border
+ int mItemWidth; // width of all items
+ uint mMaxFieldLines; // Max lines to dispaly pr field
+ CardViewItem *mCurrentItem;
+ QPoint mLastClickPos;
+ QTimer *mTimer; // times out if mouse rests for more than 500 msecs
+ CardViewTip *mTip; // passed to the item under a resting cursor to display full text
+ bool mOnSeparator; // set/reset on mouse movement
+ // for resizing by dragging the separators
+ int mResizeAnchor; // uint, ulong? the mouse down separator left
+ int mRubberBandAnchor; // for erasing rubber bands
+ // data used for resizing.
+ // as they are beeded by each mouse move while resizing, we store them here,
+ // saving 8 calculations in each mouse move.
+ int colspace; // amount of space between items pr column
+ uint first; // the first col to anchor at for painting rubber bands
+ int firstX; // X position of first in pixel
+ int pressed; // the colummn that was pressed on at resizing start
+ int span; // pressed - first
+ // key completion
+ QString mCompText; // current completion string
+ QDateTime mCompUpdated; // ...was updated at this time
+};
+
+class CardViewItemPrivate
+{
+ public:
+ CardViewItemPrivate() :
+ x( 0 ),
+ y( 0 ),
+ mSelected( false ){};
+
+
+ QString mCaption;
+ QPtrList< CardViewItem::Field > mFieldList;
+ bool mSelected;
+ int x; // horizontal position, set by the view
+ int y; // vertical position, set by the view
+ int maxLabelWidth; // the width of the widest label, according to the view font.
+ int hcache; // height cache
+};
+//END Private Data
+
+//BEGIN CardViewItem
+
+CardViewItem::CardViewItem(CardView *parent, QString caption)
+ : d(new CardViewItemPrivate()), mView(parent)
+{
+ d->mCaption = caption;
+
+ initialize();
+}
+
+CardViewItem::~CardViewItem()
+{
+ // Remove ourself from the view
+ if (mView != 0)
+ mView->takeItem(this);
+
+ delete d;
+ d = 0;
+}
+
+void CardViewItem::initialize()
+{
+ d->mSelected = false;
+ d->mFieldList.setAutoDelete(true);
+ d->maxLabelWidth = 0;
+ d->hcache=0;
+
+ //calcRect();
+
+ // Add ourself to the view
+ if (mView != 0)
+ mView->insertItem(this);
+}
+
+void CardViewItem::paintCard(QPainter *p, QColorGroup &cg)
+{
+
+ if (!mView)
+ return;
+
+ QPen pen;
+ QBrush brush;
+ QFontMetrics fm = *(mView->d->mFm);
+ QFontMetrics bFm = *(mView->d->mBFm);
+ bool drawLabels = mView->d->mDrawFieldLabels;
+ bool drawBorder = mView->d->mDrawCardBorder;
+ int mg = mView->itemMargin();
+ int w = mView->itemWidth() - (mg*2);
+ int h = height() - (mg*2);
+ const int colonWidth( fm.width(":") );
+ int labelXPos = 2 + mg;
+ int labelWidth = QMIN( w/2 - 4 - mg, d->maxLabelWidth + colonWidth + 4 );
+ int valueXPos = labelWidth + 4 + mg;
+ int valueWidth = w - labelWidth - 4 - mg;
+
+ p->setFont( mView->font() );
+ labelWidth -= colonWidth; // extra space for the colon
+
+ if (!drawLabels)
+ {
+ valueXPos = labelXPos;
+ valueWidth = w - 4;
+ }
+
+ // Draw a simple box
+ if (isSelected())
+ pen = QPen(cg.highlight(), 1);
+ else
+ pen = QPen(cg.button(), 1);
+ p->setPen(pen);
+
+ // Draw the border - this is only draw if the user asks for it.
+ if (drawBorder)
+ p->drawRect( mg, mg, w, h );
+
+ // set the proper pen color for the caption box
+ if (isSelected())
+ brush = cg.brush(QColorGroup::Highlight);
+ else
+ brush = cg.brush(QColorGroup::Button);
+
+ p->fillRect(mg, mg, w, 4 + bFm.height(), brush);
+
+ // Now paint the caption
+ p->save();
+ QFont bFont = mView->headerFont();
+ //bFont.setBold(true);
+ p->setFont(bFont);
+ if (isSelected())
+ p->setPen(cg.highlightedText());
+ else
+ p->setPen(cg.buttonText());
+ p->drawText(2+mg, 2+mg + bFm.ascent()/*bFm.height()*//*-bFm.descent()*//*-bFm.leading()*/, trimString(d->mCaption, w-4, bFm));
+ p->restore();
+
+ // Go through the fields and draw them
+ QPtrListIterator< CardViewItem::Field > iter(d->mFieldList);
+ QString label, value;
+ int yPos = mg + 4 + bFm.height()/* + 1*/ + fm.height(); // why the + 1 ??? (anders)
+ p->setPen(cg.text());
+
+ int fh = fm.height();
+ int cln( 0 );
+ QString tmp;
+ int maxLines = mView->maxFieldLines();
+ for (iter.toFirst(); iter.current(); ++iter)
+ {
+ value = (*iter)->second;
+ if ( value.isEmpty() && ! mView->d->mShowEmptyFields )
+ continue;
+
+ if (drawLabels)
+ {
+ label = trimString((*iter)->first, labelWidth, fm);
+ p->drawText(labelXPos, yPos, label + ":");
+ }
+/* US original
+ for (cln=0; cln <= maxLines; cln++)
+ {
+ tmp = value.section('\n',cln,cln);
+ if ( !tmp.isEmpty() ) p->drawText( valueXPos, yPos + cln*fh, trimString( tmp, valueWidth, fm ) );
+ else break;
+ }
+*/
+
+//US new implementation
+ QStringList strlst = QStringList::split('\n', value, true);
+
+ for (cln=0; cln <= maxLines && cln <= (int)strlst.count(); cln++)
+ {
+ tmp = strlst[cln];
+
+ if ( !tmp.isEmpty() )
+ p->drawText( valueXPos, yPos + cln*fh, trimString( tmp, valueWidth, fm ) );
+ else
+ break;
+
+ }
+
+ if ( cln == 0 ) cln = 1;
+ yPos += cln * fh + 2;
+ }
+
+ // if we are the current item and the view has focus, draw focus rect
+ if ( mView->currentItem() == this && mView->hasFocus() )
+ {
+/*US
+ mView->style().drawPrimitive( QStyle::PE_FocusRect, p,
+ QRect(0, 0, mView->itemWidth(), h+(2*mg)), cg,
+ QStyle::Style_FocusAtBorder,
+ QStyleOption( isSelected() ? cg.highlight() : cg.base() ) );
+*/
+
+ const QColor pHighl = isSelected() ? cg.highlight() : cg.base();
+ const QRect r(0, 0, mView->itemWidth(), h+(2*mg));
+#ifndef DESKTOP_VERSION
+ mView->style().drawFocusRect(p, r, cg, &pHighl, true);
+#endif
+ }
+}
+
+const QString &CardViewItem::caption() const
+{
+ return d->mCaption;
+}
+
+
+int CardViewItem::height( bool allowCache ) const
+{
+ // use cache
+ if ( allowCache && d->hcache )
+ return d->hcache;
+
+ // Base height:
+ // 2 for line width
+ // 2 for top caption pad
+ // 2 for bottom caption pad
+ // 2 pad for the end
+ // + 2 times the advised margin
+ int baseHeight = 8 + ( 2 * mView->itemMargin() );
+
+ // size of font for each field
+ // 2 pad for each field
+
+ // anders: if the view does not show empty fields, check for value
+ bool sef = mView->showEmptyFields();
+ int fh = mView->d->mFm->height();//lineSpacing(); // font height
+ //int sp = QMAX( 0, 2- mView->d->mFm->leading() ); // field spacing NOTE make a property
+ int fieldHeight = 0;
+ int lines;
+ int maxLines( mView->maxFieldLines() );
+ QPtrListIterator< CardViewItem::Field > iter(d->mFieldList);
+ for (iter.toFirst(); iter.current(); ++iter)
+ {
+ if ( !sef && (*iter)->second.isEmpty() )
+ continue;
+ lines = QMIN( (*iter)->second.contains('\n') + 1, maxLines );
+ fieldHeight += ( lines * fh ) + 2;//sp;
+ }
+
+ // height of caption font (bold)
+ fieldHeight += mView->d->mBFm->height();
+ d->hcache = baseHeight + fieldHeight;
+ return d->hcache;
+}
+
+bool CardViewItem::isSelected() const
+{
+ return d->mSelected;
+}
+
+void CardViewItem::setSelected(bool selected)
+{
+ d->mSelected = selected;
+}
+
+void CardViewItem::insertField(const QString &label, const QString &value)
+{
+ CardViewItem::Field *f = new CardViewItem::Field(label, value);
+ d->mFieldList.append(f);
+ d->hcache=0;
+
+ if (mView)
+ {
+ mView->setLayoutDirty(true);
+ d->maxLabelWidth = QMAX( mView->d->mFm->width( label ), d->maxLabelWidth );
+ }
+}
+
+void CardViewItem::removeField(const QString &label)
+{
+ CardViewItem::Field *f;
+
+ QPtrListIterator< CardViewItem::Field > iter(d->mFieldList);
+ for (iter.toFirst(); iter.current(); ++iter)
+ {
+ f = *iter;
+ if (f->first == label)
+ break;
+ }
+
+ if (*iter)
+ d->mFieldList.remove(*iter);
+ d->hcache = 0;
+
+ if (mView)
+ mView->setLayoutDirty(true);
+}
+
+void CardViewItem::clearFields()
+{
+ d->mFieldList.clear();
+ d->hcache = 0;
+
+ if (mView)
+ mView->setLayoutDirty(true);
+}
+
+QString CardViewItem::trimString(const QString &text, int width,
+ QFontMetrics &fm)
+{
+ if (fm.width(text) <= width)
+ return text;
+
+ QString dots = "...";
+ int dotWidth = fm.width(dots);
+ QString trimmed;
+ int charNum = 0;
+
+ while (fm.width(trimmed) + dotWidth < width)
+ {
+ trimmed += text[charNum];
+ charNum++;
+ }
+
+ // Now trim the last char, since it put the width over the top
+ trimmed = trimmed.left(trimmed.length()-1);
+ trimmed += dots;
+
+ return trimmed;
+}
+
+CardViewItem *CardViewItem::nextItem()
+{
+ CardViewItem *item = 0;
+
+ if (mView)
+ item = mView->itemAfter(this);
+
+ return item;
+}
+
+void CardViewItem::repaintCard()
+{
+ if (mView)
+ mView->repaintItem(this);
+}
+
+void CardViewItem::setCaption(const QString &caption)
+{
+ d->mCaption = caption;
+ repaintCard();
+}
+
+QString CardViewItem::fieldValue(const QString &label)
+{
+ QPtrListIterator< CardViewItem::Field > iter(d->mFieldList);
+ for (iter.toFirst(); iter.current(); ++iter)
+ if ((*iter)->first == label)
+ return (*iter)->second;
+
+ return QString();
+}
+
+
+void CardViewItem::showFullString( const QPoint &itempos, CardViewTip *tip )
+{
+ bool trimmed( false );
+ QString s;
+ int mrg = mView->itemMargin();
+ int y = mView->d->mBFm->height() + 6 + mrg;
+ int w = mView->itemWidth() - (2*mrg);
+ int lw;
+ bool drawLabels = mView->drawFieldLabels();
+ bool isLabel = drawLabels && itempos.x() < w/2 ? true : false;
+
+ if ( itempos.y() < y )
+ {
+ if ( itempos.y() < 8 + mrg || itempos.y() > y - 4 )
+ return;
+ // this is the caption
+ s = caption();
+ trimmed = mView->d->mBFm->width( s ) > w - 4;
+ y = 2 + mrg;
+ lw = 0;
+ isLabel=true;
+ } else {
+ // find the field
+ Field *f = fieldAt( itempos );
+ if ( !f || ( !mView->showEmptyFields() && f->second.isEmpty() ) )
+ return;
+
+ // y position:
+ // header font height + 4px hader margin + 2px leading + item margin
+ // + actual field index * (fontheight + 2px leading)
+ int maxLines = mView->maxFieldLines();
+ bool se = mView->showEmptyFields();
+ int fh = mView->d->mFm->height();
+// {
+ Field *_f;
+ for (_f = d->mFieldList.first(); _f != f; _f = d->mFieldList.next())
+ if ( se || ! _f->second.isEmpty() )
+ y += ( QMIN(_f->second.contains('\n')+1, maxLines) * fh ) + 2;
+// }
+ if ( isLabel && itempos.y() > y + fh )
+ return;
+ // label or data?
+ s = isLabel ? f->first : f->second;
+ // trimmed?
+ int colonWidth = mView->d->mFm->width(":");
+ lw = drawLabels ? // label width
+ QMIN( w/2 - 4 - mrg, d->maxLabelWidth + colonWidth + 4 ) :
+ 0;
+ int mw = isLabel ? lw - colonWidth : w - lw - (mrg*2); // max width for string
+ if ( isLabel )
+ {
+ trimmed = mView->d->mFm->width( s ) > mw - colonWidth;
+ } else {
+ QRect r( mView->d->mFm->boundingRect( 0, 0, INT_MAX, INT_MAX, Qt::AlignTop|Qt::AlignLeft, s ) );
+ trimmed = r.width() > mw || r.height()/fh > QMIN(s.contains('\n') + 1, maxLines);
+ }
+ }
+ if ( trimmed )
+ {
+ tip->setFont( (isLabel && !lw) ? mView->headerFont() : mView->font() ); // if condition is true, a header
+ tip->setText( s );
+ tip->adjustSize();
+ // find a proper position
+ int lx;
+ lx = isLabel || !drawLabels ? mrg : lw + mrg + 2 /*-1*/;
+ QPoint pnt(mView->contentsToViewport( QPoint(d->x, d->y) ));
+ pnt += QPoint(lx, y);
+ if ( pnt.x() < 0 )
+ pnt.setX( 0 );
+ if ( pnt.x() + tip->width() > mView->visibleWidth() )
+ pnt.setX( mView->visibleWidth() - tip->width() );
+ if ( pnt.y() + tip->height() > mView->visibleHeight() )
+ pnt.setY( QMAX( 0, mView->visibleHeight() - tip->height() ) );
+ // show
+ tip->move( pnt );
+ tip->show();
+ }
+}
+
+CardViewItem::Field *CardViewItem::fieldAt( const QPoint & itempos ) const
+{
+ int ypos = mView->d->mBFm->height() + 7 + mView->d->mItemMargin;
+ int iy = itempos.y();
+ // skip below caption
+ if ( iy <= ypos )
+ return 0;
+ // try find a field
+ bool showEmpty = mView->showEmptyFields();
+ int fh = mView->d->mFm->height();
+ int maxLines = mView->maxFieldLines();
+ Field *f;
+ for ( f = d->mFieldList.first(); f; f = d->mFieldList.next() )
+ {
+ if ( showEmpty || !f->second.isEmpty() )
+ ypos += ( QMIN( f->second.contains('\n')+1, maxLines ) *fh)+2;
+ if ( iy <= ypos )
+ break;
+ }
+ return f ? f : 0;
+}
+//END CardViewItem
+
+//BEGIN CardView
+
+CardView::CardView(QWidget *parent, const char *name)
+ : QScrollView(parent, name),
+ d(new CardViewPrivate())
+{
+ d->mItemList.setAutoDelete(true);
+ d->mSeparatorList.setAutoDelete(true);
+
+ QFont f = font();
+ d->mFm = new QFontMetrics(f);
+ f.setBold(true);
+ d->mHeaderFont = f;
+ d->mBFm = new QFontMetrics(f);
+ d->mTip = ( new CardViewTip( viewport() ) ),
+ d->mTip->hide();
+ d->mTimer = ( new QTimer(this, "mouseTimer") ),
+
+ viewport()->setMouseTracking( true );
+ viewport()->setFocusProxy(this);
+ viewport()->setFocusPolicy(WheelFocus);
+ viewport()->setBackgroundMode(PaletteBase);
+
+ connect( d->mTimer, SIGNAL(timeout()), this, SLOT(tryShowFullText()) );
+
+//US setBackgroundMode(PaletteBackground, PaletteBase);
+ setBackgroundMode(PaletteBackground);
+
+ // no reason for a vertical scrollbar
+ setVScrollBarMode(AlwaysOff);
+}
+
+CardView::~CardView()
+{
+ delete d->mFm;
+ delete d->mBFm;
+ delete d;
+ d = 0;
+}
+
+void CardView::insertItem(CardViewItem *item)
+{
+ d->mItemList.inSort(item);
+ setLayoutDirty(true);
+}
+
+void CardView::takeItem(CardViewItem *item)
+{
+ if ( d->mCurrentItem == item )
+ d->mCurrentItem = item->nextItem();
+ d->mItemList.take(d->mItemList.findRef(item));
+
+ setLayoutDirty(true);
+}
+
+void CardView::clear()
+{
+ d->mItemList.clear();
+
+ setLayoutDirty(true);
+}
+
+CardViewItem *CardView::currentItem()
+{
+ if ( ! d->mCurrentItem && d->mItemList.count() )
+ d->mCurrentItem = d->mItemList.first();
+ return d->mCurrentItem;
+}
+
+void CardView::setCurrentItem( CardViewItem *item )
+{
+ if ( !item )
+ return;
+ else if ( item->cardView() != this )
+ {
+ kdDebug(5720)<<"CardView::setCurrentItem: Item ("<<item<<") not owned! Backing out.."<<endl;
+ return;
+ }
+ else if ( item == currentItem() )
+ {
+ return;
+ }
+
+ if ( d->mSelectionMode == Single )
+ {
+ setSelected( item, true );
+ }
+ else
+ {
+ CardViewItem *it = d->mCurrentItem;
+ d->mCurrentItem = item;
+ if ( it )
+ it->repaintCard();
+ item->repaintCard();
+ }
+ if ( ! d->mOnSeparator )
+ ensureItemVisible( item );
+ emit currentChanged( item );
+}
+
+CardViewItem *CardView::itemAt(const QPoint &viewPos)
+{
+ CardViewItem *item = 0;
+ QPtrListIterator<CardViewItem> iter(d->mItemList);
+ bool found = false;
+ for (iter.toFirst(); iter.current() && !found; ++iter)
+ {
+ item = *iter;
+ //if (item->d->mRect.contains(viewPos))
+ if (QRect(item->d->x, item->d->y, d->mItemWidth, item->height()).contains(viewPos))
+ found = true;
+ }
+
+ if (found)
+ return item;
+
+ return 0;
+}
+
+QRect CardView::itemRect(const CardViewItem *item)
+{
+ //return item->d->mRect;
+ return QRect(item->d->x, item->d->y, d->mItemWidth, item->height());
+}
+
+void CardView::ensureItemVisible(const CardViewItem *item)
+{
+ ensureVisible(item->d->x , item->d->y, d->mItemSpacing, 0);
+ ensureVisible(item->d->x + d->mItemWidth, item->d->y, d->mItemSpacing, 0);
+}
+
+void CardView::repaintItem(const CardViewItem *item)
+{
+ //repaintContents(item->d->mRect);
+ repaintContents( QRect(item->d->x, item->d->y, d->mItemWidth, item->height()) );
+}
+
+void CardView::setSelectionMode(CardView::SelectionMode mode)
+{
+ selectAll(false);
+
+ d->mSelectionMode = mode;
+}
+
+CardView::SelectionMode CardView::selectionMode() const
+{
+ return d->mSelectionMode;
+}
+
+void CardView::selectAll(bool state)
+{
+ QPtrListIterator<CardViewItem> iter(d->mItemList);
+ if (!state)
+ {
+ for (iter.toFirst(); iter.current(); ++iter)
+ {
+ if ((*iter)->isSelected())
+ {
+ (*iter)->setSelected(false);
+ (*iter)->repaintCard();
+ }
+ }
+ //emit selectionChanged(); // WARNING FIXME
+ emit selectionChanged(0);
+ }
+ else if (d->mSelectionMode != CardView::Single)
+ {
+ for (iter.toFirst(); iter.current(); ++iter)
+ {
+ (*iter)->setSelected(true);
+ }
+
+ if (d->mItemList.count() > 0)
+ {
+ // emit, since there must have been at least one selected
+ emit selectionChanged();
+ //repaint();//???
+ viewport()->update();
+ }
+ }
+}
+
+void CardView::setSelected(CardViewItem *item, bool selected)
+{
+ if ((item == 0) || (item->isSelected() == selected))
+ return;
+
+ if ( selected && d->mCurrentItem != item )
+ {
+ CardViewItem *it = d->mCurrentItem;
+ d->mCurrentItem = item;
+ if ( it )
+ it->repaintCard();
+ }
+
+ if (d->mSelectionMode == CardView::Single)
+ {
+ bool b = signalsBlocked();
+ blockSignals(true);
+ selectAll(false);
+ blockSignals(b);
+
+ if (selected)
+ {
+ item->setSelected(selected);
+ item->repaintCard();
+ emit selectionChanged();
+ emit selectionChanged(item);
+ }
+ else
+ {
+ emit selectionChanged();
+ emit selectionChanged(0);
+ }
+ }
+ else if (d->mSelectionMode == CardView::Multi)
+ {
+ item->setSelected(selected);
+ item->repaintCard();
+ emit selectionChanged();
+ }
+ else if (d->mSelectionMode == CardView::Extended)
+ {
+ bool b = signalsBlocked();
+ blockSignals(true);
+ selectAll(false);
+ blockSignals(b);
+
+ item->setSelected(selected);
+ item->repaintCard();
+ emit selectionChanged();
+ }
+}
+
+bool CardView::isSelected(CardViewItem *item) const
+{
+ return (item && item->isSelected());
+}
+
+CardViewItem *CardView::selectedItem() const
+{
+ // find the first selected item
+ QPtrListIterator<CardViewItem> iter(d->mItemList);
+ for (iter.toFirst(); iter.current(); ++iter)
+ {
+ if ((*iter)->isSelected())
+ return *iter;
+ }
+
+ return 0;
+}
+
+CardViewItem *CardView::firstItem() const
+{
+ return d->mItemList.first();
+}
+
+int CardView::childCount() const
+{
+ return d->mItemList.count();
+}
+/*US
+CardViewItem *CardView::findItem(const QString &text, const QString &label,
+ Qt::StringComparisonMode compare)
+{
+ // IF the text is empty, we will return null, since empty text will
+ // match anything!
+ if (text.isEmpty())
+ return 0;
+
+ QPtrListIterator<CardViewItem> iter(d->mItemList);
+ if (compare & Qt::BeginsWith)
+ {
+ QString value;
+ for (iter.toFirst(); iter.current(); ++iter)
+ {
+ value = (*iter)->fieldValue(label).upper();
+ if (value.startsWith(text.upper()))
+ return *iter;
+ }
+ }
+ else
+ {
+ kdDebug(5720) << "CardView::findItem: search method not implemented" << endl;
+ }
+
+ return 0;
+}
+*/
+
+uint CardView::columnWidth()
+{
+ return d->mDrawSeparators ?
+ d->mItemWidth + ( 2 * d->mItemSpacing ) + d->mSepWidth :
+ d->mItemWidth + d->mItemSpacing;
+}
+
+void CardView::drawContents(QPainter *p, int clipx, int clipy,
+ int clipw, int cliph)
+{
+ QScrollView::drawContents(p, clipx, clipy, clipw, cliph);
+
+ if (d->mLayoutDirty)
+ calcLayout();
+
+ //kdDebug() << "CardView::drawContents: " << clipx << ", " << clipy
+ // << ", " << clipw << ", " << cliph << endl;
+
+ QColorGroup cg = viewport()->palette().active(); // allow setting costum colors in the viewport pale
+
+ QRect clipRect(clipx, clipy, clipw, cliph);
+ QRect cardRect;
+ QRect sepRect;
+ CardViewItem *item;
+ CardViewSeparator *sep;
+
+ // make sure the viewport is a pure background
+ viewport()->erase(clipRect);
+
+ // Now tell the cards to draw, if they are in the clip region
+ QPtrListIterator<CardViewItem> iter(d->mItemList);
+ for (iter.toFirst(); iter.current(); ++iter)
+ {
+ item = *iter;
+ cardRect.setRect( item->d->x, item->d->y, d->mItemWidth, item->height() );
+
+ if (clipRect.intersects(cardRect) || clipRect.contains(cardRect))
+ {
+ //kdDebug() << "\trepainting card at: " << cardRect.x() << ", "
+ // << cardRect.y() << endl;
+
+ // Tell the card to paint
+ p->save();
+ p->translate(cardRect.x(), cardRect.y());
+ item->paintCard(p, cg);
+ p->restore();
+ }
+ }
+
+ // Followed by the separators if they are in the clip region
+ QPtrListIterator<CardViewSeparator> sepIter(d->mSeparatorList);
+ for (sepIter.toFirst(); sepIter.current(); ++sepIter)
+ {
+ sep = *sepIter;
+ sepRect = sep->mRect;
+
+ if (clipRect.intersects(sepRect) || clipRect.contains(sepRect))
+ {
+ p->save();
+ p->translate(sepRect.x(), sepRect.y());
+ sep->paintSeparator(p, cg);
+ p->restore();
+ }
+ }
+}
+
+void CardView::resizeEvent(QResizeEvent *e)
+{
+ QScrollView::resizeEvent(e);
+
+ setLayoutDirty(true);
+}
+
+void CardView::calcLayout()
+{
+ //kdDebug() << "CardView::calcLayout:" << endl;
+
+ // Start in the upper left corner and layout all the
+ // cars using their height and width
+ int maxWidth = 0;
+ int maxHeight = 0;
+ int xPos = 0;
+ int yPos = 0;
+ int cardSpacing = d->mItemSpacing;
+
+ // delete the old separators
+ d->mSeparatorList.clear();
+
+ QPtrListIterator<CardViewItem> iter(d->mItemList);
+ CardViewItem *item = 0;
+ CardViewSeparator *sep = 0;
+ xPos += cardSpacing;
+
+ for (iter.toFirst(); iter.current(); ++iter)
+ {
+ item = *iter;
+
+ yPos += cardSpacing;
+
+ if (yPos + item->height() + cardSpacing >= height() - horizontalScrollBar()->height())
+ {
+ maxHeight = QMAX(maxHeight, yPos);
+
+ // Drawing in this column would be greater than the height
+ // of the scroll view, so move to next column
+ yPos = cardSpacing;
+ xPos += cardSpacing + maxWidth;
+ if (d->mDrawSeparators)
+ {
+ // Create a separator since the user asked
+ sep = new CardViewSeparator(this);
+ sep->mRect.moveTopLeft(QPoint(xPos, yPos+d->mItemMargin));
+ xPos += d->mSepWidth + cardSpacing;
+ d->mSeparatorList.append(sep);
+ }
+
+ maxWidth = 0;
+ }
+
+ item->d->x = xPos;
+ item->d->y = yPos;
+
+ yPos += item->height();
+ maxWidth = QMAX(maxWidth, d->mItemWidth);
+ }
+
+ xPos += maxWidth;
+ resizeContents( xPos + cardSpacing, maxHeight );
+
+ // Update the height of all the separators now that we know the
+ // max height of a column
+ QPtrListIterator<CardViewSeparator> sepIter(d->mSeparatorList);
+ for (sepIter.toFirst(); sepIter.current(); ++sepIter)
+ {
+ (*sepIter)->mRect.setHeight(maxHeight - 2*cardSpacing - 2*d->mItemMargin);
+ }
+
+ d->mLayoutDirty = false;
+}
+
+CardViewItem *CardView::itemAfter(CardViewItem *item)
+{
+ /*int pos = */d->mItemList.findRef(item);
+ return d->mItemList.next();//at(pos+1);
+}
+
+uint CardView::itemMargin()
+{
+ return d->mItemMargin;
+}
+
+void CardView::setItemMargin( uint margin )
+{
+ if ( margin == d->mItemMargin )
+ return;
+
+ d->mItemMargin = margin;
+ setLayoutDirty( true );
+}
+
+uint CardView::itemSpacing()
+{
+ return d->mItemSpacing;
+}
+
+void CardView::setItemSpacing( uint spacing )
+{
+ if ( spacing == d->mItemSpacing )
+ return;
+
+ d->mItemSpacing = spacing;
+ setLayoutDirty( true );
+}
+
+void CardView::contentsMousePressEvent(QMouseEvent *e)
+{
+ QScrollView::contentsMousePressEvent(e);
+
+ QPoint pos = e->pos();
+ d->mLastClickPos = pos;
+
+ CardViewItem *item = itemAt(pos);
+
+ if (item == 0)
+ {
+ d->mLastClickOnItem = false;
+ if ( d->mOnSeparator)
+ {
+ d->mResizeAnchor = e->x()+contentsX();
+ d->colspace = (2*d->mItemSpacing) /*+ (2*d->mItemMargin)*/;
+ int ccw = d->mItemWidth + d->colspace + d->mSepWidth;
+ d->first = (contentsX()+d->mSepWidth)/ccw;
+ d->pressed = (d->mResizeAnchor+d->mSepWidth)/ccw;
+ d->span = d->pressed - d->first;
+ d->firstX = d->first * ccw;
+ if ( d->firstX ) d->firstX -= d->mSepWidth; // (no sep in col 0)
+ }
+ else
+ {
+ selectAll(false);
+ }
+ return;
+ }
+
+ d->mLastClickOnItem = true;
+
+ CardViewItem *other = d->mCurrentItem;
+ setCurrentItem( item );
+
+ // Always emit the selection
+ emit clicked(item);
+
+ // Check the selection type and update accordingly
+ if (d->mSelectionMode == CardView::Single)
+ {
+ // make sure it isn't already selected
+ if (item->isSelected())
+ return;
+
+ bool b = signalsBlocked();
+ blockSignals(true);
+ selectAll(false);
+ blockSignals(b);
+
+ item->setSelected(true);
+ item->repaintCard();
+ emit selectionChanged(item);
+ }
+
+ else if (d->mSelectionMode == CardView::Multi)
+ {
+ // toggle the selection
+ item->setSelected(!item->isSelected());
+ item->repaintCard();
+ emit selectionChanged();
+ }
+
+ else if (d->mSelectionMode == CardView::Extended)
+ {
+ if ((e->button() & Qt::LeftButton) &&
+ (e->state() & Qt::ShiftButton))
+ {
+ if ( item == other ) return;
+
+ bool s = ! item->isSelected();
+
+ if ( s && ! (e->state() & ControlButton) )
+ {
+ bool b = signalsBlocked();
+ blockSignals(true);
+ selectAll(false);
+ blockSignals(b);
+ }
+
+ int from, to, a, b;
+ a = d->mItemList.findRef( item );
+ b = d->mItemList.findRef( other );
+ from = a < b ? a : b;
+ to = a > b ? a : b;
+ //kdDebug()<<"selecting items "<<from<<" - "<<to<<" ( "<<s<<" )"<<endl;
+ CardViewItem *aItem;
+ for ( ; from <= to; from++ )
+ {
+ aItem = d->mItemList.at( from );
+ aItem->setSelected( s );
+ repaintItem( aItem );
+ }
+ emit selectionChanged();
+ }
+ else if ((e->button() & Qt::LeftButton) &&
+ (e->state() & Qt::ControlButton))
+ {
+ item->setSelected(!item->isSelected());
+ item->repaintCard();
+ emit selectionChanged();
+ }
+
+ else if (e->button() & Qt::LeftButton)
+ {
+ bool b = signalsBlocked();
+ blockSignals(true);
+ selectAll(false);
+ blockSignals(b);
+
+ item->setSelected(true);
+ item->repaintCard();
+ emit selectionChanged();
+ }
+ }
+
+}
+
+void CardView::contentsMouseReleaseEvent(QMouseEvent *e)
+{
+ QScrollView::contentsMouseReleaseEvent(e);
+
+ if ( d->mResizeAnchor )
+ {
+ // finish the resizing:
+ unsetCursor();
+ // hide rubber bands
+ int newiw = d->mItemWidth - ((d->mResizeAnchor - d->mRubberBandAnchor)/d->span);
+ drawRubberBands( 0 );
+ // we should move to reflect the new position if we are scrolled.
+ if ( contentsX() )
+ {
+ int newX = QMAX( 0, ( d->pressed * ( newiw + d->colspace + d->mSepWidth ) ) - e->x() );
+ setContentsPos( newX, contentsY() );
+ }
+ // set new item width
+ setItemWidth( newiw );
+ // reset anchors
+ d->mResizeAnchor = 0;
+ d->mRubberBandAnchor = 0;
+ return;
+ }
+
+ // If there are accel keys, we will not emit signals
+ if ((e->state() & Qt::ShiftButton) || (e->state() & Qt::ControlButton))
+ return;
+
+ // Get the item at this position
+ CardViewItem *item = itemAt(e->pos());
+
+ if (item && KGlobalSettings::singleClick())
+ {
+ emit executed(item);
+ }
+}
+
+void CardView::contentsMouseDoubleClickEvent(QMouseEvent *e)
+{
+ QScrollView::contentsMouseDoubleClickEvent(e);
+
+ CardViewItem *item = itemAt(e->pos());
+
+ if (item)
+ {
+ d->mCurrentItem = item;
+ }
+
+ if (item && !KGlobalSettings::singleClick())
+ {
+ emit executed(item);
+ }
+ emit doubleClicked(item);
+}
+
+void CardView::contentsMouseMoveEvent( QMouseEvent *e )
+{
+ // resizing
+ if ( d->mResizeAnchor )
+ {
+ int x = e->x();
+ if ( x != d->mRubberBandAnchor )
+ drawRubberBands( x );
+ return;
+ }
+
+ if (d->mLastClickOnItem && (e->state() & Qt::LeftButton) &&
+ ((e->pos() - d->mLastClickPos).manhattanLength() > 4)) {
+
+ startDrag();
+ return;
+ }
+
+ d->mTimer->start( 500 );
+
+ // see if we are over a separator
+ // only if we actually have them painted?
+ if ( d->mDrawSeparators )
+ {
+ int colcontentw = d->mItemWidth + (2*d->mItemSpacing);
+ int colw = colcontentw + d->mSepWidth;
+ int m = e->x()%colw;
+ if ( m >= colcontentw && m > 0 )
+ {
+ setCursor( SplitVCursor ); // Why does this fail sometimes?
+ d->mOnSeparator = true;
+ }
+ else
+ {
+ setCursor( ArrowCursor );
+ d->mOnSeparator = false;
+ }
+ }
+}
+
+void CardView::enterEvent( QEvent * )
+{
+ d->mTimer->start( 500 );
+}
+
+void CardView::leaveEvent( QEvent * )
+{
+ d->mTimer->stop();
+ if (d->mOnSeparator)
+ {
+ d->mOnSeparator = false;
+ setCursor( ArrowCursor );
+ }
+}
+
+void CardView::focusInEvent( QFocusEvent * )
+{
+ if (!d->mCurrentItem && d->mItemList.count() )
+ {
+ setCurrentItem( d->mItemList.first() );
+ }
+ else if ( d->mCurrentItem )
+ {
+ d->mCurrentItem->repaintCard();
+ }
+}
+
+void CardView::focusOutEvent( QFocusEvent * )
+{
+ if (d->mCurrentItem)
+ d->mCurrentItem->repaintCard();
+}
+
+void CardView::keyPressEvent( QKeyEvent *e )
+{
+ if ( ! ( childCount() && d->mCurrentItem ) )
+ {
+ e->ignore();
+ return;
+ }
+
+ uint pos = d->mItemList.findRef( d->mCurrentItem );
+ CardViewItem *aItem = 0L; // item that gets the focus
+ CardViewItem *old = d->mCurrentItem;
+
+ switch ( e->key() )
+ {
+ case Key_Up:
+ if ( pos > 0 )
+ {
+ aItem = d->mItemList.at( pos - 1 );
+ setCurrentItem( aItem );
+ }
+ break;
+ case Key_Down:
+ if ( pos < d->mItemList.count() - 1 )
+ {
+ aItem = d->mItemList.at( pos + 1 );
+ setCurrentItem( aItem );
+ }
+ break;
+ case Key_Left:
+ {
+ // look for an item in the previous/next column, starting from
+ // the vertical middle of the current item.
+ // FIXME use nice calculatd measures!!!
+ QPoint aPoint( d->mCurrentItem->d->x, d->mCurrentItem->d->y );
+ aPoint -= QPoint( 30,-(d->mCurrentItem->height()/2) );
+ aItem = itemAt( aPoint );
+ // maybe we hit some space below an item
+ while ( !aItem && aPoint.y() > 27 )
+ {
+ aPoint -= QPoint( 0, 16 );
+ aItem = itemAt( aPoint );
+ }
+ if ( aItem )
+ setCurrentItem( aItem );
+ }
+ break;
+ case Key_Right:
+ {
+ // FIXME use nice calculated measures!!!
+ QPoint aPoint( d->mCurrentItem->d->x + d->mItemWidth, d->mCurrentItem->d->y );
+ aPoint += QPoint( 30,(d->mCurrentItem->height()/2) );
+ aItem = itemAt( aPoint );
+ while ( !aItem && aPoint.y() > 27 )
+ {
+ aPoint -= QPoint( 0, 16 );
+ aItem = itemAt( aPoint );
+ }
+ if ( aItem )
+ setCurrentItem( aItem );
+ }
+ break;
+ case Key_Home:
+ aItem = d->mItemList.first();
+ setCurrentItem( aItem );
+ break;
+ case Key_End:
+ aItem = d->mItemList.last();
+ setCurrentItem( aItem );
+ break;
+ case Key_Prior: // PageUp
+ {
+ // QListView: "Make the item above the top visible and current"
+ // TODO if contentsY(), pick the top item of the leftmost visible column
+ if ( contentsX() <= 0 )
+ return;
+ int cw = columnWidth();
+ int theCol = ( QMAX( 0, ( contentsX()/cw) * cw ) ) + d->mItemSpacing;
+ aItem = itemAt( QPoint( theCol + 1, d->mItemSpacing + 1 ) );
+ if ( aItem )
+ setCurrentItem( aItem );
+ }
+ break;
+ case Key_Next: // PageDown
+ {
+ // QListView: "Make the item below the bottom visible and current"
+ // find the first not fully visible column.
+ // TODO: consider if a partly visible (or even hidden) item at the
+ // bottom of the rightmost column exists
+ int cw = columnWidth();
+ int theCol = ( (( contentsX() + visibleWidth() )/cw) * cw ) + d->mItemSpacing + 1;
+ // if separators are on, we may need to we may be one column further right if only the spacing/sep is hidden
+ if ( d->mDrawSeparators && cw - (( contentsX() + visibleWidth() )%cw) <= int( d->mItemSpacing + d->mSepWidth ) )
+ theCol += cw;
+
+ // make sure this is not too far right
+ while ( theCol > contentsWidth() )
+ theCol -= columnWidth();
+
+ aItem = itemAt( QPoint( theCol, d->mItemSpacing + 1 ) );
+
+ if ( aItem )
+ setCurrentItem( aItem );
+ }
+ break;
+ case Key_Space:
+ setSelected( d->mCurrentItem, !d->mCurrentItem->isSelected() );
+ emit selectionChanged();
+ break;
+ case Key_Return:
+ case Key_Enter:
+ emit returnPressed( d->mCurrentItem );
+ emit executed( d->mCurrentItem );
+ break;
+ default:
+ if ( (e->state() & ControlButton) && e->key() == Key_A )
+ {
+ // select all
+ selectAll( true );
+ break;
+ }
+ // if we have a string, do autosearch
+ else if ( ! e->text().isEmpty() && e->text()[0].isPrint() )
+ {
+
+ }
+ break;
+ }
+ // handle selection
+ if ( aItem )
+ {
+ if ( d->mSelectionMode == CardView::Extended )
+ {
+ if ( (e->state() & ShiftButton) )
+ {
+ // shift button: toggle range
+ // if control button is pressed, leave all items
+ // and toggle selection current->old current
+ // otherwise, ??????
+ bool s = ! aItem->isSelected();
+ int from, to, a, b;
+ a = d->mItemList.findRef( aItem );
+ b = d->mItemList.findRef( old );
+ from = a < b ? a : b;
+ to = a > b ? a : b;
+
+ if ( to - from > 1 )
+ {
+ bool b = signalsBlocked();
+ blockSignals(true);
+ selectAll(false);
+ blockSignals(b);
+ }
+
+ //kdDebug()<<"selecting items "<<from<<" - "<<to<<" ( "<<s<<" )"<<endl;
+ CardViewItem *item;
+ for ( ; from <= to; from++ )
+ {
+ item = d->mItemList.at( from );
+ item->setSelected( s );
+ repaintItem( item );
+ }
+ emit selectionChanged();
+ }
+ else if ( (e->state() & ControlButton) )
+ {
+ // control button: do nothing
+ }
+ else
+ {
+ // no button: move selection to this item
+ bool b = signalsBlocked();
+ blockSignals(true);
+ selectAll(false);
+ blockSignals(b);
+
+ setSelected( aItem, true );
+ emit selectionChanged();
+ }
+ }
+ }
+}
+
+void CardView::contentsWheelEvent( QWheelEvent * e )
+{
+ scrollBy(2*e->delta()/-3, 0);
+}
+
+void CardView::setLayoutDirty(bool dirty)
+{
+ if (d->mLayoutDirty != dirty)
+ {
+ d->mLayoutDirty = dirty;
+ repaint();
+ }
+}
+
+void CardView::setDrawCardBorder(bool enabled)
+{
+ if (enabled != d->mDrawCardBorder)
+ {
+ d->mDrawCardBorder = enabled;
+ repaint();
+ }
+}
+
+bool CardView::drawCardBorder() const
+{
+ return d->mDrawCardBorder;
+}
+
+void CardView::setDrawColSeparators(bool enabled)
+{
+ if (enabled != d->mDrawSeparators)
+ {
+ d->mDrawSeparators = enabled;
+ setLayoutDirty(true);
+ }
+}
+
+bool CardView::drawColSeparators() const
+{
+ return d->mDrawSeparators;
+}
+
+void CardView::setDrawFieldLabels(bool enabled)
+{
+ if (enabled != d->mDrawFieldLabels)
+ {
+ d->mDrawFieldLabels = enabled;
+ repaint();
+ }
+}
+
+bool CardView::drawFieldLabels() const
+{
+ return d->mDrawFieldLabels;
+}
+
+void CardView::setShowEmptyFields(bool show)
+{
+ if (show != d->mShowEmptyFields)
+ {
+ d->mShowEmptyFields = show;
+ setLayoutDirty(true);
+ }
+}
+
+bool CardView::showEmptyFields() const
+{
+ return d->mShowEmptyFields;
+}
+
+void CardView::startDrag()
+{
+ // The default implementation is a no-op. It must be
+ // reimplemented in a subclass to be useful
+}
+void CardView::tryShowFullText()
+{
+ d->mTimer->stop();
+ // if we have an item
+ QPoint cpos = viewportToContents( viewport()->mapFromGlobal( QCursor::pos() ) );
+ CardViewItem *item = itemAt( cpos );
+ if ( item )
+ {
+ // query it for a value to display
+ //QString s = item ? item->caption() : "(no item)";
+ //kdDebug()<<"MOUSE REST: "<<s<<endl;
+ QPoint ipos = cpos - itemRect( item ).topLeft();
+ item->showFullString( ipos, d->mTip );
+ }
+}
+
+void CardView::drawRubberBands( int pos )
+{
+ if ( pos && ((pos-d->firstX)/d->span) - d->colspace - d->mSepWidth < MIN_ITEM_WIDTH ) return;
+
+ int tmpcw = (d->mRubberBandAnchor-d->firstX)/d->span;
+ int x = d->firstX + tmpcw - d->mSepWidth - contentsX();
+ int h = visibleHeight();
+
+ QPainter p( viewport() );
+ p.setRasterOp( XorROP );
+ p.setPen( gray );
+ p.setBrush( gray );
+ uint n = d->first;
+ // erase
+ if ( d->mRubberBandAnchor )
+ do {
+ p.drawRect( x, 0, 2, h );
+ x += tmpcw;
+ n++;
+ } while ( x < visibleWidth() && n < d->mSeparatorList.count() );
+ // paint new
+ if ( ! pos ) return;
+ tmpcw = (pos - d->firstX)/d->span;
+ n = d->first;
+ x = d->firstX + tmpcw - d->mSepWidth - contentsX();
+ do {
+ p.drawRect( x, 0, 2, h );
+ x += tmpcw;
+ n++;
+ } while ( x < visibleWidth() && n < d->mSeparatorList.count() );
+ d->mRubberBandAnchor = pos;
+}
+
+
+int CardView::itemWidth() const
+{
+ return d->mItemWidth;
+}
+
+void CardView::setItemWidth( int w )
+{
+ if ( w == d->mItemWidth )
+ return;
+ if ( w < MIN_ITEM_WIDTH )
+ w = MIN_ITEM_WIDTH;
+ d->mItemWidth = w;
+ setLayoutDirty( true );
+#ifndef KAB_EMBEDDED
+ updateContents();
+#else //KAB_EMBEDDED
+//US updateContents( d->contentsX(), d->contentsY(), visibleWidth(), visibleHeight() );
+qDebug("CardView::setItemWidth has to be verified");
+ updateContents( contentsX(), contentsY(), visibleWidth(), visibleHeight() );
+#endif //KAB_EMBEDDED
+}
+
+void CardView::setHeaderFont( const QFont &fnt )
+{
+ d->mHeaderFont = fnt;
+ delete d->mBFm;
+ d->mBFm = new QFontMetrics( fnt );
+}
+
+QFont CardView::headerFont() const
+{
+ return d->mHeaderFont;
+}
+
+void CardView::setFont( const QFont &fnt )
+{
+ QScrollView::setFont( fnt );
+ delete d->mFm;
+ d->mFm = new QFontMetrics( fnt );
+}
+
+int CardView::separatorWidth()
+{
+ return d->mSepWidth;
+}
+
+void CardView::setSeparatorWidth( int width )
+{
+ d->mSepWidth = width;
+ setLayoutDirty( true ); // hmm, actually I could just adjust the x'es...
+}
+
+int CardView::maxFieldLines() const
+{
+ return d->mMaxFieldLines;
+}
+
+void CardView::setMaxFieldLines( int howmany )
+{
+ d->mMaxFieldLines = howmany ? howmany : INT_MAX;
+ // FIXME update, forcing the items to recalc height!!
+}
+//END Cardview
+
+#ifndef KAB_EMBEDDED
+#include "cardview.moc"
+#endif //KAB_EMBEDDED
diff --git a/kaddressbook/views/cardview.desktop b/kaddressbook/views/cardview.desktop
new file mode 100644
index 0000000..8507360
--- a/dev/null
+++ b/kaddressbook/views/cardview.desktop
@@ -0,0 +1,18 @@
+[Desktop Entry]
+Encoding=UTF-8
+X-KDE-Library=libkaddrbk_cardview
+Name=Card View
+Name[be]=У выглядзе картак
+Name[ca]=Vista de targeta
+Name[da]=Kort-visning
+Name[el]=Προβολή καρτών
+Name[es]=Vista de tarjeta
+Name[hu]=Kártyanézet
+Name[pt_BR]=Visualização de Cartão
+Name[ru]=Карточка
+Name[sk]=Prezeranie karty
+Name[sv]=Kortvy
+Name[tr]=Kart Görünümü
+Name[zh_CN]=卡片视图
+Type=Service
+ServiceTypes=KAddressBook/View
diff --git a/kaddressbook/views/cardview.h b/kaddressbook/views/cardview.h
new file mode 100644
index 0000000..37dddb6
--- a/dev/null
+++ b/kaddressbook/views/cardview.h
@@ -0,0 +1,473 @@
+#ifndef CARDVIEW_H
+#define CARDVIEW_H
+
+#include <qscrollview.h>
+#include <qptrlist.h>
+#include <qstring.h>
+#include <qrect.h>
+#include <qpair.h>
+#include <qpoint.h>
+
+class QLabel;
+class QPainter;
+class QResizeEvent;
+class QMouseEvent;
+class CardView;
+class CardViewPrivate;
+class CardViewItemPrivate;
+class CardViewTip;
+
+/** Represents a single card (item) in the card view. A card has a caption
+* and a list of fields. A Field is a label<->value pair. The labels in a
+* card should be unique, since they will be used to index the values.
+*/
+class CardViewItem
+{
+ friend class CardView;
+
+ public:
+ /** A single field in the card view. The first item is the label
+ * and the second item is the value.
+ */
+ typedef QPair<QString, QString> Field;
+
+ /** Constructor.
+ *
+ * @param parent The CardView that this card should be displayed on.
+ * @param caption The caption of the card. This is the text that will
+ * appear at the top of the card. This is also the string that will
+ * be used to sort the cards in the view.
+ */
+ CardViewItem(CardView *parent, QString caption = QString::null);
+ virtual ~CardViewItem();
+
+ /** @return The caption of the card, or QString::null if none was ever
+ * set.
+ */
+ const QString &caption() const;
+
+ /** Sets the caption of the card. This is the text that will
+ * appear at the top of the card. This is also the string that will
+ * be used to sort the cards in the view.
+ */
+ void setCaption(const QString &caption);
+
+ /** Paints the card using the given painter and color group. The
+ * card will handle painting itself selected if it is selected.
+ */
+ virtual void paintCard(QPainter *p, QColorGroup &cg);
+
+ /** Repaints the card. This is done by sending a repaint event to the
+ * view with the clip rect defined as this card.
+ */
+ virtual void repaintCard();
+
+ /** Adds a field to the card.
+ *
+ * @param label The label of the field. The field labels must be unique
+ * within a card.
+ * @param The value of the field.
+ */
+ void insertField(const QString &label, const QString &value);
+
+ /** Removes the field with label <i>label</i> from the card.
+ */
+ void removeField(const QString &label);
+
+ /** @return The value of the field with label <i>label</i>.
+ */
+ QString fieldValue(const QString &label);
+
+ /** Removes all the fields from this card.
+ */
+ void clearFields();
+
+ /** @return The next card item. The order of the items will be the same
+ * as the display order in the view. 0 will be returned if this is the
+ * last card.
+ */
+ CardViewItem *nextItem();
+
+ /** @return True if this card is currently selected, false otherwise.
+ */
+ bool isSelected() const;
+
+ /** Called by the parent card view when the mouse has been resting for
+ * a certain amount of time. If the label or value at pos is obscured
+ * (trimmed) make the label display the full text.
+ */
+ void showFullString( const QPoint &pos, CardViewTip *tip );
+
+ /** @return a pointer to the Field at the position itempos
+ * in this item. 0 is returned if itempos is in the caption.
+ * @param itempos the position in item coordinates
+ */
+ Field *fieldAt( const QPoint &itempos ) const;
+
+ CardView *cardView() { return mView; };
+
+ /** @return The height of this item as rendered, in pixels.
+
+ if @p allowCache is true, the item may use an internally
+ cached value rather than recalculating from scratch. The
+ argument is mainly to allow the cardView to change global settings (like
+ maxFieldLines) that might influence the items heights
+ */
+ int height( bool allowCache=true ) const;
+
+ protected:
+ /** Sets the card as selected. This is usually only called from the
+ * card view.
+ */
+ void setSelected(bool selected);
+
+ private:
+ /** Sets the default values.
+ */
+ void initialize();
+
+ /** Trims a string to the width <i>width</i> using the font metrics
+ * to determine the width of each char. If the string is longer than
+ * <i>width</i>, then the string will be trimmed and a '...' will
+ * be appended.
+ */
+ QString trimString(const QString &text, int width, QFontMetrics &fm);
+
+ CardViewItemPrivate *d;
+ CardView *mView;
+};
+
+/** The CardView is a method of displaying data in cards. This idea is
+* similar to the idea of a rolodex or business cards. Each card has a
+* caption and a list of fields, which are label<->value pairs. The CardView
+* displays multiple cards in a grid. The Cards are sorted based on their
+* caption.
+*
+* The CardView class is designed to mirror the API of the QListView or
+* QIconView. The CardView is also completely independant of KAddressBook and
+* can be used elsewhere. With the exception of a few simple config checks,
+* the CardView is also 100% independant of KDE.
+*/
+class CardView : public QScrollView
+{
+ friend class CardViewItem;
+
+ Q_OBJECT
+
+ public:
+ /** Constructor.
+ */
+ CardView(QWidget *parent, const char *name);
+ virtual ~CardView();
+
+ /** Inserts the item into the card view. This method does not have
+ * to be called if you created the item with a proper parent. Once
+ * inserted, the CardView takes ownership of the item.
+ */
+ void insertItem(CardViewItem *item);
+
+ /** Takes the item from the view. The item will not be deleted and
+ * ownership of the item is returned to the caller.
+ */
+ void takeItem(CardViewItem *item);
+
+ /** Clears the view and deletes all card view items
+ */
+ void clear();
+
+ /** @return The current item, the item that has the focus.
+ * Whenever the view has focus, this item has a focus rectangle painted
+ * at it's border.
+ * @sa setCurrentItem()
+ */
+ CardViewItem *currentItem();
+
+ /** Sets the CardViewItem @p item to the current item in the view.
+ */
+ void setCurrentItem( CardViewItem *item );
+
+ /** @return The item found at the given point, or 0 if there is no item
+ * at that point.
+ */
+ CardViewItem *itemAt(const QPoint &viewPos);
+
+ /** @return The bounding rect of the given item.
+ */
+ QRect itemRect(const CardViewItem *item);
+
+ /** Ensures that the given item is in the viewable area of the widget
+ */
+ void ensureItemVisible(const CardViewItem *item);
+
+ /** Repaints the given item.
+ */
+ void repaintItem(const CardViewItem *item);
+
+ enum SelectionMode { Single, Multi, Extended, NoSelection };
+
+ /** Sets the selection mode.
+ *
+ * @see QListView
+ */
+ void setSelectionMode(SelectionMode mode);
+
+ /** @return The current selection mode.
+ */
+ SelectionMode selectionMode() const;
+
+ /** Selects or deselects the given item. This method honors the current
+ * selection mode, so if other items are selected, they may be unselected.
+ */
+ void setSelected(CardViewItem *item, bool selected);
+
+ /** Selects or deselects all items.
+ */
+ void selectAll(bool state);
+
+ /** @return True if the given item is selected, false otherwise.
+ */
+ bool isSelected(CardViewItem *item) const;
+
+ /** @return The first selected item. In single select mode, this will be
+ * the only selected item, in other modes this will be the first selected
+ * item, but others may exist. 0 if no item is selected.
+ */
+ CardViewItem *selectedItem() const;
+
+ /** @return The first item in the view. This may be 0 if no items have
+ * been inserted. This method combined with CardViewItem::nextItem()
+ * can be used to iterator through the list of items.
+ */
+ CardViewItem *firstItem() const;
+
+ /** @return The item after the given item or 0 if the item is the last
+ * item.
+ */
+ CardViewItem *itemAfter(CardViewItem *item);
+
+ /** @return The number of items in the view.
+ */
+ int childCount() const;
+
+ /** Attempts to find the first item matching the params.
+ *
+ * @param text The text to match.
+ * @param label The label of the field to match against.
+ * @param compare The compare method to use in doing the search.
+ *
+ * @return The first matching item, or 0 if no items match.
+ */
+/*US
+ CardViewItem *findItem(const QString &text, const QString &label,
+ Qt::StringComparisonMode compare = Qt::BeginsWith);
+*/
+
+ /** Returns the amounts of pixels required for one column.
+ * This depends on wheather drawSeparators is enabled:
+ * If so, it is itemWidth + 2*itemSpacing + separatorWidth
+ * If not, it is itemWidth + itemSpacing
+ * @see itemWidth(), setItemWidth(), itemSpacing() and setItemSpacing()
+ */
+ uint columnWidth();
+
+ /** Sets if the border around a card should be draw. The border is a thing
+ * (1 or 2 pixel) line that bounds the card. When drawn, it shows when
+ * a card is highlighted and when it isn't.
+ */
+ void setDrawCardBorder(bool enabled);
+
+ /** @return True if borders are drawn, false otherwise.
+ */
+ bool drawCardBorder() const;
+
+ /** Sets if the column separator should be drawn. The column separator
+ * is a thin verticle line (1 or 2 pixels) that is used to separate the
+ * columns in the list view. The separator is just for esthetics and it
+ * does not serve a functional purpose.
+ */
+ void setDrawColSeparators(bool enabled);
+
+ /** @return True if column separators are drawn, false otherwise.
+ */
+ bool drawColSeparators() const;
+
+ /** Sets if the field labels should be drawn. The field labels are the
+ * unique strings used to identify the fields. Sometimes drawing these
+ * labels makes sense as a source of clarity for the user, othertimes they
+ * waste too much space and do not assist the user.
+ */
+ void setDrawFieldLabels(bool enabled);
+
+ /** @return True if the field labels are drawn, false otherwise.
+ */
+ bool drawFieldLabels() const;
+
+ /** Sets if fields with no value should be drawn (of cause the label only,
+ * but it allows for embedded editing sometimes...)
+ */
+ void setShowEmptyFields(bool show);
+
+ /** @return Wheather empty fields should be shown
+ */
+ bool showEmptyFields() const;
+
+ /** @return the advisory internal margin in items. Setting a value above 1 means
+ * a space between the item contents and the focus recttangle drawn around
+ * the current item. The default value is 0.
+ * The value should be used by CardViewItem and derived classes.
+ * Note that this should not be greater than half of the minimal item width,
+ * which is 80. It is currently not checked, so setting a value greater than 40
+ * will probably mean a crash in the items painting routine.
+ * @private Note: I looked for a value in QStyle::PixelMetric to use, but I could
+ * not see a usefull one. One may turn up in a future version of Qt.
+ */
+ uint itemMargin();
+
+ /** Sets the internal item margin. @see itemMargin().
+ */
+ void setItemMargin( uint margin );
+
+ /** @return the item spacing.
+ * The item spacing is the space (in pixels) between each item in a
+ * column, between the items and column separators if drawn, and between
+ * the items and the borders of the widget. The default value is set to
+ * 10.
+ * @private Note: There is no usefull QStyle::PixelMetric to use for this atm.
+ * An option would be using KDialog::spacingHint().
+ */
+ uint itemSpacing();
+
+ /** Sets the item spacing.
+ * @see itemSpacing()
+ */
+ void setItemSpacing( uint spacing );
+
+ /** @return the width made available to the card items. */
+ int itemWidth() const;
+
+ /** Sets the width made available to card items. */
+ void setItemWidth( int width );
+
+ /** Sets the header font */
+ void setHeaderFont( const QFont &fnt );
+
+ /** @return the header font */
+ QFont headerFont() const;
+
+ /** @reimp */
+ void setFont( const QFont &fnt );
+
+ /** Sets the column separator width */
+ void setSeparatorWidth( int width );
+
+ /** @return the column separator width */
+ int separatorWidth();
+
+ /** Sets the maximum number of lines to display pr field.
+ If set to 0 (the default) all lines will be displayed.
+ */
+ void setMaxFieldLines( int howmany );
+
+ /** @return the maximum number of lines pr field */
+ int maxFieldLines() const;
+
+ signals:
+ /** Emitted whenever the selection changes. This means a user highlighted
+ * a new item or unhighlighted a currently selected item.
+ */
+ void selectionChanged();
+
+ /** Same as above method, only it carries the item that was selected. This
+ * method will only be emitted in single select mode, since it defineds
+ * which item was selected.
+ */
+ void selectionChanged(CardViewItem *);
+
+ /** This method is emitted whenever an item is clicked.
+ */
+ void clicked(CardViewItem *);
+
+ /** Emitted whenever the user 'executes' an item. This is dependant on
+ * the KDE global config. This could be a single click or a doubleclick.
+ * Also emitted when the return key is pressed on an item.
+ */
+ void executed(CardViewItem *);
+
+ /** Emitted whenever the user double clicks on an item.
+ */
+ void doubleClicked(CardViewItem *);
+
+ /** Emitted when the current item changes
+ */
+ void currentChanged( CardViewItem * );
+
+ /** Emitted when the return key is pressed in an item.
+ */
+ void returnPressed( CardViewItem * );
+
+ protected:
+ /** Determines which cards intersect that region and tells them to paint
+ * themselves.
+ */
+ void drawContents(QPainter *p, int clipx, int clipy, int clipw, int cliph);
+
+ /** Sets the layout to dirty and repaints.
+ */
+ void resizeEvent(QResizeEvent *e);
+
+ /** Changes the direction the canvas scolls.
+ */
+ void contentsWheelEvent(QWheelEvent *e);
+
+ /** Sets the layout to dirty and calls for a repaint.
+ */
+ void setLayoutDirty(bool dirty);
+
+ /** Does the math based on the bounding rect of the cards to properly
+ * lay the cards out on the screen. This is only done if the layout is
+ * marked as dirty.
+ */
+ void calcLayout();
+
+// virtual void mousePressEvent(QMouseEvent *e);
+// virtual void mouseReleaseEvent(QMouseEvent *e);
+// virtual void mouseMoveEvent(QMouseEvent *e);
+
+ virtual void contentsMousePressEvent(QMouseEvent *e);
+ virtual void contentsMouseMoveEvent(QMouseEvent *e);
+ virtual void contentsMouseReleaseEvent(QMouseEvent *e);
+ virtual void contentsMouseDoubleClickEvent(QMouseEvent *e);
+
+ virtual void enterEvent( QEvent * );
+ virtual void leaveEvent( QEvent * );
+
+ virtual void focusInEvent( QFocusEvent * );
+ virtual void focusOutEvent( QFocusEvent * );
+
+ virtual void keyPressEvent( QKeyEvent * );
+
+ /** Overload this method to be told when a drag should be started.
+ * In most cases you will want to start a drag event with the currently
+ * selected item.
+ */
+ virtual void startDrag();
+
+ private slots:
+ /** Called by a timer to display a label with truncated text.
+ * Pop up a label, if there is a field with obscured text or
+ * label at the cursor position.
+ */
+ void tryShowFullText();
+
+ private:
+ /** draws and erases the rubber bands while columns are resized.
+ * @p pos is the horizontal position inside the viewport to use as
+ * the anchor.
+ * If pos is 0, only erase is done.
+ */
+ void drawRubberBands( int pos );
+
+ CardViewPrivate *d;
+};
+
+#endif
diff --git a/kaddressbook/views/colorlistbox.cpp b/kaddressbook/views/colorlistbox.cpp
new file mode 100644
index 0000000..c243fa0
--- a/dev/null
+++ b/kaddressbook/views/colorlistbox.cpp
@@ -0,0 +1,230 @@
+/*
+ * kmail: KDE mail client
+ * This file: Copyright (C) 2000 Espen Sand, espen@kde.org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#include <qpainter.h>
+
+#include <kcolordialog.h>
+
+#ifndef KAB_EMBEDDED
+#include <kcolordrag.h>
+#endif //KAB_EMBEDDED
+
+#include "colorlistbox.h"
+
+ColorListBox::ColorListBox( QWidget *parent, const char *name, WFlags f )
+ :KListBox( parent, name, f ), mCurrentOnDragEnter(-1)
+{
+ connect( this, SIGNAL(selected(int)), this, SLOT(newColor(int)) );
+ setAcceptDrops( true);
+}
+
+
+void ColorListBox::setEnabled( bool state )
+{
+ if( state == isEnabled() )
+ {
+ return;
+ }
+
+ QListBox::setEnabled( state );
+ for( uint i=0; i<count(); i++ )
+ {
+ updateItem( i );
+ }
+}
+
+
+void ColorListBox::setColor( uint index, const QColor &color )
+{
+ if( index < count() )
+ {
+ ColorListItem *colorItem = (ColorListItem*)item(index);
+ colorItem->setColor(color);
+ updateItem( colorItem );
+ }
+}
+
+
+QColor ColorListBox::color( uint index ) const
+{
+ if( index < count() )
+ {
+ ColorListItem *colorItem = (ColorListItem*)item(index);
+ return( colorItem->color() );
+ }
+ else
+ {
+ return( black );
+ }
+}
+
+
+void ColorListBox::newColor( int index )
+{
+ if( isEnabled() == false )
+ {
+ return;
+ }
+
+ if( (uint)index < count() )
+ {
+ QColor c = color( index );
+#ifndef KAB_EMBEDDED
+ if( KColorDialog::getColor( c, this ) != QDialog::Rejected )
+ {
+ setColor( index, c );
+ }
+#else //KAB_EMBEDDED
+ KColorDialog* k = new KColorDialog( this );
+ k->setColor( c );
+ int res = k->exec();
+ if ( res ) {
+ setColor( index, k->getColor() );
+ }
+ delete k;
+#endif //KAB_EMBEDDED
+
+ }
+}
+
+
+void ColorListBox::dragEnterEvent( QDragEnterEvent *e )
+{
+#ifndef KAB_EMBEDDED
+ if( KColorDrag::canDecode(e) && isEnabled() )
+ {
+ mCurrentOnDragEnter = currentItem();
+ e->accept( true );
+ }
+ else
+ {
+ mCurrentOnDragEnter = -1;
+ e->accept( false );
+ }
+#else //KAB_EMBEDDED
+qDebug("ColorListBox::dragEnterEvent drag&drop currently not supported");
+#endif //KAB_EMBEDDED
+
+}
+
+
+void ColorListBox::dragLeaveEvent( QDragLeaveEvent * )
+{
+#ifndef KAB_EMBEDDED
+
+ if( mCurrentOnDragEnter != -1 )
+ {
+ setCurrentItem( mCurrentOnDragEnter );
+ mCurrentOnDragEnter = -1;
+ }
+#else //KAB_EMBEDDED
+qDebug("ColorListBox::dragLeaveEvent drag&drop currently not supported");
+#endif //KAB_EMBEDDED
+}
+
+
+void ColorListBox::dragMoveEvent( QDragMoveEvent *e )
+{
+#ifndef KAB_EMBEDDED
+ if( KColorDrag::canDecode(e) && isEnabled() )
+ {
+ ColorListItem *item = (ColorListItem*)itemAt( e->pos() );
+ if( item != 0 )
+ {
+ setCurrentItem ( item );
+ }
+ }
+#else //KAB_EMBEDDED
+qDebug("ColorListBox::dragMoveEvent drag&drop currently not supported");
+#endif //KAB_EMBEDDED
+
+}
+
+
+void ColorListBox::dropEvent( QDropEvent *e )
+{
+#ifndef KAB_EMBEDDED
+ QColor color;
+ if( KColorDrag::decode( e, color ) )
+ {
+ int index = currentItem();
+ if( index != -1 )
+ {
+ ColorListItem *colorItem = (ColorListItem*)item(index);
+ colorItem->setColor(color);
+ triggerUpdate( false ); // Redraw item
+ }
+ mCurrentOnDragEnter = -1;
+ }
+
+#else //KAB_EMBEDDED
+qDebug("ColorListBox::dropEvent drag&drop currently not supported");
+#endif //KAB_EMBEDDED
+
+}
+
+
+
+ColorListItem::ColorListItem( const QString &text, const QColor &color )
+ : QListBoxItem(), mColor( color ), mBoxWidth( 30 )
+{
+ setText( text );
+}
+
+
+const QColor &ColorListItem::color( void )
+{
+ return( mColor );
+}
+
+
+void ColorListItem::setColor( const QColor &color )
+{
+ mColor = color;
+}
+
+
+void ColorListItem::paint( QPainter *p )
+{
+ QFontMetrics fm = p->fontMetrics();
+ int h = fm.height();
+
+ p->drawText( mBoxWidth+3*2, fm.ascent() + fm.leading()/2, text() );
+
+ p->setPen( Qt::black );
+ p->drawRect( 3, 1, mBoxWidth, h-1 );
+ p->fillRect( 4, 2, mBoxWidth-2, h-3, mColor );
+}
+
+
+int ColorListItem::height(const QListBox *lb ) const
+{
+ return( lb->fontMetrics().lineSpacing()+1 );
+}
+
+
+int ColorListItem::width(const QListBox *lb ) const
+{
+ return( mBoxWidth + lb->fontMetrics().width( text() ) + 6 );
+}
+
+#ifndef KAB_EMBEDDED
+#include "colorlistbox.moc"
+#endif //KAB_EMBEDDED
diff --git a/kaddressbook/views/colorlistbox.h b/kaddressbook/views/colorlistbox.h
new file mode 100644
index 0000000..4a0e705
--- a/dev/null
+++ b/kaddressbook/views/colorlistbox.h
@@ -0,0 +1,76 @@
+/*
+ * kmail: KDE mail client
+ * This file: Copyright (C) 2000 Espen Sand, espen@kde.org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifndef _COLOR_LISTBOX_H_
+#define _COLOR_LISTBOX_H_
+
+#include <klistbox.h>
+
+class QDragEnterEvent;
+class QDragLeaveEvent;
+class QDragMoveEvent;
+class QDropEvent;
+
+class ColorListBox : public KListBox
+{
+ Q_OBJECT
+
+ public:
+ ColorListBox( QWidget *parent=0, const char * name=0, WFlags f=0 );
+ void setColor( uint index, const QColor &color );
+ QColor color( uint index ) const;
+
+ public slots:
+ virtual void setEnabled( bool state );
+
+ protected:
+ void dragEnterEvent( QDragEnterEvent *e );
+ void dragLeaveEvent( QDragLeaveEvent *e );
+ void dragMoveEvent( QDragMoveEvent *e );
+ void dropEvent( QDropEvent *e );
+
+ private slots:
+ void newColor( int index );
+
+ private:
+ int mCurrentOnDragEnter;
+
+};
+
+
+class ColorListItem : public QListBoxItem
+{
+ public:
+ ColorListItem( const QString &text, const QColor &color=Qt::black );
+ const QColor &color( void );
+ void setColor( const QColor &color );
+
+ protected:
+ virtual void paint( QPainter * );
+ virtual int height( const QListBox * ) const;
+ virtual int width( const QListBox * ) const;
+
+ private:
+ QColor mColor;
+ int mBoxWidth;
+};
+
+#endif
+
diff --git a/kaddressbook/views/configurecardviewdialog.cpp b/kaddressbook/views/configurecardviewdialog.cpp
new file mode 100644
index 0000000..d518cf7
--- a/dev/null
+++ b/kaddressbook/views/configurecardviewdialog.cpp
@@ -0,0 +1,364 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include <qstring.h>
+#include <qlayout.h>
+#include <qlabel.h>
+#include <qcheckbox.h>
+#include <qvbox.h>
+#include <qgroupbox.h>
+#include <qspinbox.h>
+#include <qtabwidget.h>
+#include <qwhatsthis.h>
+
+#include <kdebug.h>
+#include <kglobal.h>
+#include <kglobalsettings.h>
+#include <klocale.h>
+#include <kiconloader.h>
+#include <kconfig.h>
+#include <kfontdialog.h>
+
+#ifndef KAB_EMBEDDED
+#include <kpushbutton.h>
+#else //KAB_EMBEDDED
+#include <qpushbutton.h>
+#endif //KAB_EMBEDDED
+
+#include "colorlistbox.h"
+
+#include "configurecardviewdialog.h"
+
+/////////////////////////////////
+// ConfigureCardViewDialog
+
+ConfigureCardViewWidget::ConfigureCardViewWidget( KABC::AddressBook *ab, QWidget *parent,
+ const char *name )
+ : ViewConfigureWidget( ab, parent, name )
+{
+#ifndef KAB_EMBEDDED
+ QWidget *page = addPage( i18n( "Look & Feel" ), QString::null,
+ DesktopIcon( "looknfeel" ) );
+#else //KAB_EMBEDDED
+ QWidget *page = addPage( i18n( "Look & Feel" ), QString::null,
+ KGlobal::iconLoader()->loadIcon( "looknfeel",
+ KIcon::Panel ) );
+#endif //KAB_EMBEDDED
+
+ mAdvancedPage = new CardViewLookNFeelPage( page );
+}
+
+ConfigureCardViewWidget::~ConfigureCardViewWidget()
+{
+}
+
+void ConfigureCardViewWidget::restoreSettings( KConfig *config )
+{
+ ViewConfigureWidget::restoreSettings( config );
+
+ mAdvancedPage->restoreSettings( config );
+}
+
+void ConfigureCardViewWidget::saveSettings( KConfig *config )
+{
+ ViewConfigureWidget::saveSettings( config );
+
+ mAdvancedPage->saveSettings( config );
+}
+
+////////////////////////
+// CardViewLookNFeelPage
+CardViewLookNFeelPage::CardViewLookNFeelPage( QWidget *parent, const char *name )
+ : QVBox( parent, name )
+{
+ initGUI();
+}
+
+CardViewLookNFeelPage::~CardViewLookNFeelPage()
+{
+}
+
+void CardViewLookNFeelPage::restoreSettings( KConfig *config )
+{
+ // colors
+ cbEnableCustomColors->setChecked( config->readBoolEntry( "EnableCustomColors", false ) );
+ QColor c;
+qDebug("CardViewLookNFeelPage::restoreSettings make base color configurable");
+
+#ifndef KAB_EMBEDDED
+ c = KGlobalSettings::baseColor();
+#else //KAB_EMBEDDED
+ c = QColor(0,0,0);
+#endif //KAB_EMBEDDED
+
+ lbColors->insertItem( new ColorListItem( i18n("Background Color"),
+ config->readColorEntry( "BackgroundColor", &c ) ) );
+ c = colorGroup().foreground();
+ lbColors->insertItem( new ColorListItem( i18n("Text Color"),
+ config->readColorEntry( "TextColor", &c ) ) );
+ c = colorGroup().button();
+ lbColors->insertItem( new ColorListItem( i18n("Header, Border and Separator Color"),
+ config->readColorEntry( "HeaderColor", &c ) ) );
+ c = colorGroup().buttonText();
+ lbColors->insertItem( new ColorListItem( i18n("Header Text Color"),
+ config->readColorEntry( "HeaderTextColor", &c ) ) );
+ c = colorGroup().highlight();
+ lbColors->insertItem( new ColorListItem( i18n("Highlight Color"),
+ config->readColorEntry( "HighlightColor", &c ) ) );
+ c = colorGroup().highlightedText();
+ lbColors->insertItem( new ColorListItem( i18n("Highlighted Text Color"),
+ config->readColorEntry( "HighlightedTextColor", &c ) ) );
+
+ enableColors();
+
+ // fonts
+ QFont fnt = font();
+ updateFontLabel( config->readFontEntry( "TextFont", &fnt ), (QLabel*)lTextFont );
+ fnt.setBold( true );
+ updateFontLabel( config->readFontEntry( "HeaderFont", &fnt ), (QLabel*)lHeaderFont );
+ cbEnableCustomFonts->setChecked( config->readBoolEntry( "EnableCustomFonts", false ) );
+ enableFonts();
+
+ // layout
+ sbMargin->setValue( config->readNumEntry( "ItemMargin", 0 ) );
+ sbSpacing->setValue( config->readNumEntry( "ItemSpacing", 10 ) );
+ sbSepWidth->setValue( config->readNumEntry( "SeparatorWidth", 2 ) );
+ cbDrawSeps->setChecked( config->readBoolEntry( "DrawSeparators", true ) );
+ cbDrawBorders->setChecked( config->readBoolEntry( "DrawBorder", true ) );
+
+ // behaviour
+ cbShowFieldLabels->setChecked( config->readBoolEntry( "DrawFieldLabels", false ) );
+ cbShowEmptyFields->setChecked( config->readBoolEntry( "ShowEmptyFields", false ) );
+}
+
+void CardViewLookNFeelPage::saveSettings( KConfig *config )
+{
+ // colors
+ config->writeEntry( "EnableCustomColors", cbEnableCustomColors->isChecked() );
+ if ( cbEnableCustomColors->isChecked() ) // ?? - Hmmm.
+ {
+ config->writeEntry( "BackgroundColor", lbColors->color( 0 ) );
+ config->writeEntry( "TextColor", lbColors->color( 1 ) );
+ config->writeEntry( "HeaderColor", lbColors->color( 2 ) );
+ config->writeEntry( "HeaderTextColor", lbColors->color( 3 ) );
+ config->writeEntry( "HighlightColor", lbColors->color( 4 ) );
+ config->writeEntry( "HighlightedTextColor", lbColors->color( 5 ) );
+ }
+ // fonts
+ config->writeEntry( "EnableCustomFonts", cbEnableCustomFonts->isChecked() );
+ if ( cbEnableCustomFonts->isChecked() )
+ {
+ config->writeEntry( "TextFont", lTextFont->font() );
+ config->writeEntry( "HeaderFont", lHeaderFont->font() );
+ }
+ // layout
+ config->writeEntry( "ItemMargin", sbMargin->value() );
+ config->writeEntry( "ItemSpacing", sbSpacing->value() );
+ config->writeEntry( "SeparatorWidth", sbSepWidth->value() );
+ config->writeEntry("DrawBorder", cbDrawBorders->isChecked());
+ config->writeEntry("DrawSeparators", cbDrawSeps->isChecked());
+
+ // behaviour
+ config->writeEntry("DrawFieldLabels", cbShowFieldLabels->isChecked());
+ config->writeEntry("ShowEmptyFields", cbShowEmptyFields->isChecked());
+}
+
+void CardViewLookNFeelPage::setTextFont()
+{
+ QFont f( lTextFont->font() );
+#ifndef KAB_EMBEDDED
+ if ( KFontDialog::getFont( f, false, this ) == QDialog::Accepted )
+ updateFontLabel( f, lTextFont );
+#else //KAB_EMBEDDED
+ bool ok;
+ QFont fout = KFontDialog::getFont( f, ok);
+ if ( ok )
+ updateFontLabel( fout, lTextFont );
+#endif //KAB_EMBEDDED
+}
+
+void CardViewLookNFeelPage::setHeaderFont()
+{
+ QFont f( lHeaderFont->font() );
+#ifndef KAB_EMBEDDED
+ if ( KFontDialog::getFont( f,false, this ) == QDialog::Accepted )
+ updateFontLabel( f, lHeaderFont );
+#else //KAB_EMBEDDED
+ bool ok;
+ QFont fout = KFontDialog::getFont( f, ok);
+ if ( ok )
+ updateFontLabel( fout, lHeaderFont );
+#endif //KAB_EMBEDDED
+}
+
+void CardViewLookNFeelPage::enableFonts()
+{
+ vbFonts->setEnabled( cbEnableCustomFonts->isChecked() );
+}
+
+void CardViewLookNFeelPage::enableColors()
+{
+ lbColors->setEnabled( cbEnableCustomColors->isChecked() );
+}
+
+void CardViewLookNFeelPage::initGUI()
+{
+ int spacing = KDialog::spacingHint();
+ int margin = KDialog::marginHint();
+
+ QTabWidget *tabs = new QTabWidget( this );
+
+ // Layout
+ QVBox *loTab = new QVBox( this, "layouttab" );
+
+ loTab->setSpacing( spacing );
+ loTab->setMargin( margin );
+
+ QGroupBox *gbGeneral = new QGroupBox( 1, Qt::Horizontal, i18n("General"), loTab );
+
+ cbDrawSeps = new QCheckBox( i18n("Draw &separators"), gbGeneral );
+
+ QHBox *hbSW = new QHBox( gbGeneral );
+ QLabel *lSW = new QLabel( i18n("Separator &width:"), hbSW );
+ sbSepWidth = new QSpinBox( 1, 50, 1, hbSW );
+ lSW->setBuddy( sbSepWidth);
+
+ QHBox *hbPadding = new QHBox( gbGeneral );
+ QLabel *lSpacing = new QLabel( i18n("&Padding:"), hbPadding );
+ sbSpacing = new QSpinBox( 0, 100, 1, hbPadding );
+ lSpacing->setBuddy( sbSpacing );
+
+ QGroupBox *gbCards = new QGroupBox( 1, Qt::Horizontal, i18n("Cards"), loTab );
+
+ QHBox *hbMargin = new QHBox( gbCards );
+ QLabel *lMargin = new QLabel( i18n("&Margin:"), hbMargin );
+ sbMargin = new QSpinBox( 0, 100, 1, hbMargin );
+ lMargin->setBuddy( sbMargin );
+
+ cbDrawBorders = new QCheckBox( i18n("Draw &borders"), gbCards );
+
+ loTab->setStretchFactor( new QWidget( loTab ), 1 );
+
+ QWhatsThis::add( sbMargin, i18n(
+ "The item margin is the distance (in pixels) between the item edge and the item data. Most noticeably, "
+ "incrementing the item margin will add space between the focus rectangle and the item data."
+ ) );
+ QWhatsThis::add( lMargin, QWhatsThis::textFor( sbMargin ) );
+ QWhatsThis::add( sbSpacing, i18n(
+ "The Item Spacing decides the distance (in pixels) between the items and anything else: the view "
+ "borders, other items or column separators."
+ ) );
+ QWhatsThis::add( lSpacing, QWhatsThis::textFor( sbSpacing ) );
+ QWhatsThis::add( sbSepWidth, i18n("Sets the width of column separators") );
+ QWhatsThis::add( lSW, QWhatsThis::textFor( sbSepWidth ) );
+
+ tabs->addTab( loTab, i18n("&Layout") );
+
+ // Colors
+ QVBox *colorTab = new QVBox( this, "colortab" );
+ colorTab->setSpacing( spacing );
+ colorTab->setMargin( spacing );
+ cbEnableCustomColors = new QCheckBox( i18n("&Enable custom Colors"), colorTab );
+ connect( cbEnableCustomColors, SIGNAL(clicked()), this, SLOT(enableColors()) );
+ lbColors = new ColorListBox( colorTab );
+ tabs->addTab( colorTab, i18n("&Colors") );
+
+ QWhatsThis::add( cbEnableCustomColors, i18n(
+ "If custom colors are enabled, you may choose the colors for the view below. "
+ "Otherwise colors from your current KDE color scheme are used."
+ ) );
+ QWhatsThis::add( lbColors, i18n(
+ "Double click or press RETURN on a item to select a color for the related strings in the view."
+ ) );
+
+ // Fonts
+ QVBox *fntTab = new QVBox( this, "fonttab" );
+
+ fntTab->setSpacing( spacing );
+ fntTab->setMargin( spacing );
+
+ cbEnableCustomFonts = new QCheckBox( i18n("&Enable custom fonts"), fntTab );
+ connect( cbEnableCustomFonts, SIGNAL(clicked()), this, SLOT(enableFonts()) );
+
+ vbFonts = new QWidget( fntTab );
+ QGridLayout *gFnts = new QGridLayout( vbFonts, 2, 3 );
+ gFnts->setSpacing( spacing );
+ gFnts->setAutoAdd( true );
+ gFnts->setColStretch( 1, 1 );
+ QLabel *lTFnt = new QLabel( i18n("&Text font:"), vbFonts );
+ lTextFont = new QLabel( vbFonts );
+ lTextFont->setFrameStyle( QFrame::Panel|QFrame::Sunken );
+#ifndef KAB_EMBEDDED
+ btnFont = new KPushButton( i18n("Choose..."), vbFonts );
+#else //KAB_EMBEDDED
+ btnFont = new QPushButton( i18n("Choose..."), vbFonts );
+#endif //KAB_EMBEDDED
+
+ lTFnt->setBuddy( btnFont );
+
+ connect( btnFont, SIGNAL(clicked()), this, SLOT(setTextFont()) );
+
+ QLabel *lHFnt = new QLabel( i18n("&Header font:"), vbFonts );
+ lHeaderFont = new QLabel( vbFonts );
+ lHeaderFont->setFrameStyle( QFrame::Panel|QFrame::Sunken );
+#ifndef KAB_EMBEDDED
+ btnHeaderFont = new KPushButton( i18n("Choose..."), vbFonts );
+#else //KAB_EMBEDDED
+ btnHeaderFont = new QPushButton( i18n("Choose..."), vbFonts );
+#endif //KAB_EMBEDDED
+ lHFnt->setBuddy( btnHeaderFont );
+ connect( btnHeaderFont, SIGNAL(clicked()), this, SLOT(setHeaderFont()) );
+
+ fntTab->setStretchFactor( new QWidget( fntTab ), 1 );
+
+ QWhatsThis::add( cbEnableCustomFonts, i18n(
+ "If custom fonts are enabled, you may choose which fonts to use for this view below. "
+ "Otherwise the default KDE font will be used, in bold style for the header and "
+ "normal style for the data."
+ ) );
+
+ tabs->addTab( fntTab, i18n("&Fonts") );
+
+ // Behaviour
+ QVBox *behaviourTab = new QVBox( this );
+ behaviourTab->setMargin( margin );
+ behaviourTab->setSpacing( spacing );
+
+ cbShowEmptyFields = new QCheckBox( i18n("Show &empty fields"), behaviourTab );
+ cbShowFieldLabels = new QCheckBox( i18n("Show field &labels"), behaviourTab );
+
+ behaviourTab->setStretchFactor( new QWidget( behaviourTab ), 1 );
+
+ tabs->addTab( behaviourTab, i18n("Be&havior") );
+
+}
+
+void CardViewLookNFeelPage::updateFontLabel( QFont fnt, QLabel *l )
+{
+ l->setFont( fnt );
+ l->setText( QString( fnt.family() + " %1" ).arg( fnt.pointSize() ) );
+}
+
+#ifndef KAB_EMBEDDED
+#include "configurecardviewdialog.moc"
+#endif //KAB_EMBEDDED
diff --git a/kaddressbook/views/configurecardviewdialog.h b/kaddressbook/views/configurecardviewdialog.h
new file mode 100644
index 0000000..7a62226
--- a/dev/null
+++ b/kaddressbook/views/configurecardviewdialog.h
@@ -0,0 +1,117 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef CONFIGURECARDVIEWDIALOG_H
+#define CONFIGURECARDVIEWDIALOG_H
+
+#include "viewconfigurewidget.h"
+
+#include <qvbox.h>
+#include <qwidget.h>
+#include <qfont.h>
+
+class QString;
+class QWidget;
+class QCheckBox;
+class QLabel;
+class KConfig;
+
+namespace KABC { class AddressBook; }
+
+class CardViewLookAndFeelPage;
+
+/**
+ Configure dialog for the card view. This dialog inherits from the
+ standard view dialog in order to add a custom page for the card
+ view.
+ */
+class ConfigureCardViewWidget : public ViewConfigureWidget
+{
+ public:
+ ConfigureCardViewWidget( KABC::AddressBook *ab, QWidget *parent, const char *name );
+ virtual ~ConfigureCardViewWidget();
+
+ virtual void restoreSettings( KConfig* );
+ virtual void saveSettings( KConfig* );
+
+ private:
+ class CardViewLookNFeelPage *mAdvancedPage;
+};
+
+/**
+ Card View Advanced LookNFeel settings widget:
+ this is a tabbed widget with 3 tabs:
+ Fonts
+ * text font
+ * header font
+
+ Colors
+ * background color
+ * text color
+ * highlight color
+ * title/sep text color
+ * title/sep bg color
+
+ Layout
+ * item margin
+ * item spacing
+*/
+
+class CardViewLookNFeelPage : public QVBox {
+
+ Q_OBJECT
+
+ public:
+ CardViewLookNFeelPage( QWidget *parent=0, const char *name=0 );
+ ~CardViewLookNFeelPage();
+
+ void restoreSettings( KConfig* );
+ void saveSettings( KConfig* );
+
+ private slots:
+ void setTextFont();
+ void setHeaderFont();
+ void enableFonts();
+ void enableColors();
+
+ private:
+ void initGUI();
+ void updateFontLabel( QFont, QLabel * );
+
+ QCheckBox *cbEnableCustomFonts,
+ *cbEnableCustomColors,
+ *cbDrawSeps, *cbDrawBorders,
+ *cbShowFieldLabels, *cbShowEmptyFields;
+ class ColorListBox *lbColors;
+ QLabel *lTextFont, *lHeaderFont;
+#ifndef KAB_EMBEDDED
+ class KPushButton *btnFont, *btnHeaderFont;
+#else //KAB_EMBEDDED
+ class QPushButton *btnFont, *btnHeaderFont;
+#endif //KAB_EMBEDDED
+ class QSpinBox *sbMargin, *sbSpacing, *sbSepWidth;
+
+ class QWidget *vbFonts;
+};
+
+#endif
diff --git a/kaddressbook/views/configuretableviewdialog.cpp b/kaddressbook/views/configuretableviewdialog.cpp
new file mode 100644
index 0000000..e1cc63e
--- a/dev/null
+++ b/kaddressbook/views/configuretableviewdialog.cpp
@@ -0,0 +1,155 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include <qstring.h>
+#include <qwidget.h>
+#include <qlayout.h>
+#include <qradiobutton.h>
+#include <qcheckbox.h>
+#include <qvbox.h>
+#include <qbuttongroup.h>
+
+#include <kglobal.h>
+#include <klocale.h>
+#include <klineedit.h>
+#include <kurlrequester.h>
+#include <kiconloader.h>
+
+#ifndef KAB_EMBEDDED
+#include <kimageio.h>
+#else //KAB_EMBEDDED
+#endif //KAB_EMBEDDED
+
+#include <kconfig.h>
+
+#include "configuretableviewdialog.h"
+
+ConfigureTableViewWidget::ConfigureTableViewWidget( KABC::AddressBook *ab,
+ QWidget *parent,
+ const char *name )
+ : ViewConfigureWidget( ab, parent, name )
+{
+ QWidget *page = addPage( i18n( "Look & Feel" ), QString::null,
+ KGlobal::iconLoader()->loadIcon( "looknfeel",
+ KIcon::Panel ) );
+
+ mPage = new LookAndFeelPage( page );
+}
+
+ConfigureTableViewWidget::~ConfigureTableViewWidget()
+{
+}
+
+void ConfigureTableViewWidget::restoreSettings( KConfig *config )
+{
+ ViewConfigureWidget::restoreSettings( config );
+
+ mPage->restoreSettings( config );
+}
+
+void ConfigureTableViewWidget::saveSettings( KConfig *config )
+{
+ ViewConfigureWidget::saveSettings( config );
+
+ mPage->saveSettings( config );
+}
+
+
+
+LookAndFeelPage::LookAndFeelPage(QWidget *parent, const char *name)
+ : QWidget(parent, name)
+{
+ initGUI();
+
+ // Set initial state
+ enableBackgroundToggled(mBackgroundBox->isChecked());
+}
+
+void LookAndFeelPage::restoreSettings( KConfig *config )
+{
+ mAlternateButton->setChecked(config->readBoolEntry("ABackground", true));
+ mLineButton->setChecked(config->readBoolEntry("SingleLine", false));
+ mToolTipBox->setChecked(config->readBoolEntry("ToolTips", true));
+
+ if (!mAlternateButton->isChecked() & !mLineButton->isChecked())
+ mNoneButton->setChecked(true);
+
+ mBackgroundBox->setChecked(config->readBoolEntry("Background", false));
+ mBackgroundName->lineEdit()->setText(config->readEntry("BackgroundName"));
+}
+
+void LookAndFeelPage::saveSettings( KConfig *config )
+{
+ config->writeEntry("ABackground", mAlternateButton->isChecked());
+ config->writeEntry("SingleLine", mLineButton->isChecked());
+ config->writeEntry("ToolTips", mToolTipBox->isChecked());
+ config->writeEntry("Background", mBackgroundBox->isChecked());
+ config->writeEntry("BackgroundName", mBackgroundName->lineEdit()->text());
+}
+
+void LookAndFeelPage::initGUI()
+{
+ QVBoxLayout *layout = new QVBoxLayout(this, 0, KDialogBase::spacingHint());
+
+ QButtonGroup *group = new QButtonGroup(1, Qt::Horizontal,
+ i18n("Row Separator"), this);
+ layout->addWidget(group);
+
+ mAlternateButton = new QRadioButton(i18n("Alternating backgrounds"),
+ group, "mAlternateButton");
+ mLineButton = new QRadioButton(i18n("Single line"), group, "mLineButton");
+ mNoneButton = new QRadioButton(i18n("None"), group, "mNoneButton");
+
+ // Background Checkbox/Selector
+ QHBoxLayout *backgroundLayout = new QHBoxLayout();
+ layout->addLayout(backgroundLayout);
+
+ mBackgroundBox = new QCheckBox(i18n("Enable background image:"), this,
+ "mBackgroundBox");
+ connect(mBackgroundBox, SIGNAL(toggled(bool)),
+ SLOT(enableBackgroundToggled(bool)));
+ backgroundLayout->addWidget(mBackgroundBox);
+
+ mBackgroundName = new KURLRequester(this, "mBackgroundName");
+#ifndef KAB_EMBEDDED
+ mBackgroundName->setMode(KFile::File | KFile::ExistingOnly |
+ KFile::LocalOnly);
+ mBackgroundName->setFilter(KImageIO::pattern(KImageIO::Reading));
+#endif //KAB_EMBEDDED
+
+ backgroundLayout->addWidget(mBackgroundName);
+
+ // ToolTip Checkbox
+ mToolTipBox = new QCheckBox(i18n("Enable contact tooltips"), this,
+ "mToolTipBox");
+ layout->addWidget(mToolTipBox);
+}
+
+void LookAndFeelPage::enableBackgroundToggled(bool enabled)
+{
+ mBackgroundName->setEnabled(enabled);
+}
+
+#ifndef KAB_EMBEDDED
+#include "configuretableviewdialog.moc"
+#endif //KAB_EMBEDDED
diff --git a/kaddressbook/views/configuretableviewdialog.h b/kaddressbook/views/configuretableviewdialog.h
new file mode 100644
index 0000000..8392710
--- a/dev/null
+++ b/kaddressbook/views/configuretableviewdialog.h
@@ -0,0 +1,88 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef CONFIGURETABLEVIEWDIALOG_H
+#define CONFIGURETABLEVIEWDIALOG_H
+
+#include "viewconfigurewidget.h"
+
+class QString;
+class QWidget;
+class QRadioButton;
+class QCheckBox;
+class KURLRequester;
+class KConfig;
+
+namespace KABC { class AddressBook; }
+
+class LookAndFeelPage;
+
+/**
+ Configure dialog for the table view. This dialog inherits from the
+ standard view dialog in order to add a custom page for the table
+ view.
+ */
+class ConfigureTableViewWidget : public ViewConfigureWidget
+{
+ public:
+ ConfigureTableViewWidget( KABC::AddressBook *ab, QWidget *parent, const char *name );
+ virtual ~ConfigureTableViewWidget();
+
+ virtual void restoreSettings( KConfig* );
+ virtual void saveSettings( KConfig* );
+
+ private:
+ void initGUI();
+
+ LookAndFeelPage *mPage;
+};
+
+/**
+ Internal class. It is only defined here for moc
+*/
+class LookAndFeelPage : public QWidget
+{
+ Q_OBJECT
+
+ public:
+ LookAndFeelPage( QWidget *parent, const char *name = 0 );
+ ~LookAndFeelPage() {}
+
+ void restoreSettings( KConfig* );
+ void saveSettings( KConfig* );
+
+ protected slots:
+ void enableBackgroundToggled( bool );
+
+ private:
+ void initGUI();
+
+ QRadioButton *mAlternateButton;
+ QRadioButton *mLineButton;
+ QRadioButton *mNoneButton;
+ QCheckBox *mToolTipBox;
+ KURLRequester *mBackgroundName;
+ QCheckBox *mBackgroundBox;
+};
+
+#endif
diff --git a/kaddressbook/views/contactlistview.cpp b/kaddressbook/views/contactlistview.cpp
new file mode 100644
index 0000000..98b2fb2
--- a/dev/null
+++ b/kaddressbook/views/contactlistview.cpp
@@ -0,0 +1,340 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include <qheader.h>
+#include <qiconset.h>
+#include <qimage.h>
+#include <qdragobject.h>
+#include <qcombobox.h>
+#include <qpainter.h>
+#include <qbrush.h>
+#include <qevent.h>
+
+#include <klocale.h>
+#include <kglobalsettings.h>
+#include <kiconloader.h>
+#include <kdebug.h>
+#include <kconfig.h>
+#include <kapplication.h>
+#include <kurl.h>
+
+#include "kaddressbooktableview.h"
+
+#include "contactlistview.h"
+
+/////////////////////////////////
+// DynamicTip Methods
+
+DynamicTip::DynamicTip( ContactListView *parent)
+ : QToolTip( parent )
+{
+}
+
+void DynamicTip::maybeTip( const QPoint &pos )
+{
+ static bool ishidden = true;
+ if (!parentWidget()->inherits( "ContactListView" ))
+ return;
+
+ ContactListView *plv = (ContactListView*)parentWidget();
+ if (!plv->tooltips())
+ return;
+
+ QPoint posVp = plv->viewport()->pos();
+
+ QListViewItem *lvi = plv->itemAt( pos - posVp );
+ if (!lvi)
+ return;
+
+#ifndef KAB_EMBEDDED
+ ContactListViewItem *plvi = dynamic_cast< ContactListViewItem* >(lvi);
+#else //KAB_EMBEDDED
+ ContactListViewItem *plvi = (ContactListViewItem*)(lvi);
+#endif //KAB_EMBEDDED
+
+ if (!plvi)
+ return;
+
+ if (ishidden) {
+ QString s;
+ QRect r = plv->itemRect( lvi );
+ r.moveBy( posVp.x(), posVp.y() );
+
+ //kdDebug() << "Tip rec: " << r.x() << "," << r.y() << "," << r.width()
+ // << "," << r.height() << endl;
+
+ KABC::Addressee a = plvi->addressee();
+ if (a.isEmpty())
+ return;
+
+ s += i18n("label: value", "%1: %2").arg(a.formattedNameLabel())
+ .arg(a.formattedName());
+
+ s += '\n';
+ s += i18n("label: value", "%1: %2").arg(a.organizationLabel())
+ .arg(a.organization());
+
+ QString notes = a.note().stripWhiteSpace();
+ if ( !notes.isEmpty() ) {
+ notes += '\n';
+ s += '\n' + i18n("label: value", "%1: \n").arg(a.noteLabel());
+ QFontMetrics fm( font() );
+
+ // Begin word wrap code based on QMultiLineEdit code
+ int i = 0;
+ bool doBreak = false;
+ int linew = 0;
+ int lastSpace = -1;
+ int a = 0;
+ int lastw = 0;
+
+ while ( i < int(notes.length()) ) {
+ doBreak = FALSE;
+ if ( notes[i] != '\n' )
+ linew += fm.width( notes[i] );
+
+ if ( lastSpace >= a && notes[i] != '\n' )
+ if (linew >= parentWidget()->width()) {
+ doBreak = TRUE;
+ if ( lastSpace > a ) {
+ i = lastSpace;
+ linew = lastw;
+ }
+ else
+ i = QMAX( a, i-1 );
+ }
+
+ if ( notes[i] == '\n' || doBreak ) {
+ s += notes.mid( a, i - a + (doBreak?1:0) ) +"\n";
+
+ a = i + 1;
+ lastSpace = a;
+ linew = 0;
+ }
+
+ if ( notes[i].isSpace() ) {
+ lastSpace = i;
+ lastw = linew;
+ }
+
+ if ( lastSpace <= a ) {
+ lastw = linew;
+ }
+
+ ++i;
+ }
+ }
+
+ tip( r, s );
+ }
+ else
+ hide();
+ ishidden = !ishidden;
+
+}
+
+///////////////////////////
+// ContactListViewItem Methods
+
+ContactListViewItem::ContactListViewItem(const KABC::Addressee &a,
+ ContactListView *parent,
+ KABC::AddressBook *doc,
+ const KABC::Field::List &fields )
+ : KListViewItem(parent), mAddressee(a), mFields( fields ),
+ parentListView( parent ), mDocument(doc)
+{
+ refresh();
+}
+
+QString ContactListViewItem::key(int column, bool ascending) const
+{
+ return QListViewItem::key(column, ascending).lower();
+}
+
+void ContactListViewItem::paintCell(QPainter * p,
+ const QColorGroup & cg,
+ int column,
+ int width,
+ int align)
+{
+ KListViewItem::paintCell(p, cg, column, width, align);
+
+ if ( !p )
+ return;
+
+ if (parentListView->singleLine()) {
+ p->setPen( parentListView->alternateColor() );
+ p->drawLine( 0, height() - 1, width, height() - 1 );
+ }
+}
+
+
+ContactListView *ContactListViewItem::parent()
+{
+ return parentListView;
+}
+
+
+void ContactListViewItem::refresh()
+{
+ // Update our addressee, since it may have changed else were
+ mAddressee = mDocument->findByUid(mAddressee.uid());
+ if (mAddressee.isEmpty())
+ return;
+
+ int i = 0;
+ KABC::Field::List::ConstIterator it;
+ for( it = mFields.begin(); it != mFields.end(); ++it ) {
+ setText( i++, (*it)->value( mAddressee ) );
+ }
+}
+
+///////////////////////////////
+// ContactListView
+
+ContactListView::ContactListView(KAddressBookTableView *view,
+ KABC::AddressBook* /* doc */,
+ QWidget *parent,
+ const char *name )
+ : KListView( parent, name ),
+ pabWidget( view ),
+ oldColumn( 0 )
+{
+ mABackground = true;
+ mSingleLine = false;
+ mToolTips = true;
+#ifndef KAB_EMBEDDED
+ mAlternateColor = KGlobalSettings::alternateBackgroundColor();
+#else //KAB_EMBEDDED
+ mAlternateColor = QColor(240, 240, 240);
+#endif //KAB_EMBEDDED
+
+ setAlternateBackgroundEnabled(mABackground);
+ setAcceptDrops( true );
+ viewport()->setAcceptDrops( true );
+ setAllColumnsShowFocus( true );
+ setShowSortIndicator(true);
+
+ setSelectionModeExt( KListView::Extended );
+ setDropVisualizer(false);
+ // setFrameStyle(QFrame::NoFrame);
+ setLineWidth ( 0 );
+ setMidLineWidth ( 0 );
+ setMargin ( 0 );
+#ifndef KAB_EMBEDDED
+ connect(this, SIGNAL(dropped(QDropEvent*)),
+ this, SLOT(itemDropped(QDropEvent*)));
+#endif //KAB_EMBEDDED
+
+
+ new DynamicTip( this );
+}
+
+void ContactListView::paintEmptyArea( QPainter * p, const QRect & rect )
+{
+ QBrush b = palette().brush(QPalette::Active, QColorGroup::Base);
+
+ // Get the brush, which will have the background pixmap if there is one.
+ if (b.pixmap())
+ {
+ p->drawTiledPixmap( rect.left(), rect.top(), rect.width(), rect.height(),
+ *(b.pixmap()),
+ rect.left() + contentsX(),
+ rect.top() + contentsY() );
+ }
+
+ else
+ {
+ // Do a normal paint
+ KListView::paintEmptyArea(p, rect);
+ }
+}
+
+void ContactListView::contentsMousePressEvent(QMouseEvent* e)
+{
+ presspos = e->pos();
+ KListView::contentsMousePressEvent(e);
+}
+
+
+// To initiate a drag operation
+void ContactListView::contentsMouseMoveEvent( QMouseEvent *e )
+{
+ if ((e->state() & LeftButton) && (e->pos() - presspos).manhattanLength() > 4 ) {
+ emit startAddresseeDrag();
+ }
+ else
+ KListView::contentsMouseMoveEvent( e );
+}
+
+bool ContactListView::acceptDrag(QDropEvent *e) const
+{
+#ifndef KAB_EMBEDDED
+ return QTextDrag::canDecode(e);
+#else //KAB_EMBEDDED
+qDebug("ContactListView::acceptDrag has to be fixed");
+ return false;
+#endif //KAB_EMBEDDED
+}
+
+void ContactListView::itemDropped(QDropEvent *e)
+{
+ contentsDropEvent(e);
+}
+
+void ContactListView::contentsDropEvent( QDropEvent *e )
+{
+ emit addresseeDropped(e);
+}
+
+void ContactListView::setAlternateBackgroundEnabled(bool enabled)
+{
+ mABackground = enabled;
+
+ if (mABackground)
+ {
+ setAlternateBackground(mAlternateColor);
+ }
+ else
+ {
+ setAlternateBackground(QColor());
+ }
+}
+
+void ContactListView::setBackgroundPixmap(const QString &filename)
+{
+ if (filename.isEmpty())
+ {
+ unsetPalette();
+ }
+ else
+ {
+ qDebug("ContactListView::setBackgroundPixmap has to be verified");
+//US setPaletteBackgroundPixmap(QPixmap(filename));
+ KListView::setBackgroundPixmap((const QPixmap&)QPixmap(filename));
+ }
+
+}
+#ifndef KAB_EMBEDDED
+#include "contactlistview.moc"
+#endif //KAB_EMBEDDED
diff --git a/kaddressbook/views/contactlistview.h b/kaddressbook/views/contactlistview.h
new file mode 100644
index 0000000..ae9c994
--- a/dev/null
+++ b/kaddressbook/views/contactlistview.h
@@ -0,0 +1,128 @@
+#ifndef CONTACTLISTVIEW_H
+#define CONTACTLISTVIEW_H
+
+#include <qcolor.h>
+#include <qpixmap.h>
+#include <qtooltip.h>
+#include <qstring.h>
+
+#include <klistview.h>
+
+#include <kabc/field.h>
+#include <kabc/addressee.h>
+#include <kabc/addressbook.h>
+
+
+class QDropEvent;
+class KAddressBookTableView;
+class ContactListView;
+
+/** The whole tooltip design needs a lot of work. Currently it is
+* hacked together to function.
+*/
+class DynamicTip : public QToolTip
+{
+ public:
+ DynamicTip( ContactListView * parent );
+
+ protected:
+ void maybeTip( const QPoint & );
+
+ private:
+};
+
+class ContactListViewItem : public KListViewItem
+{
+
+public:
+ ContactListViewItem(const KABC::Addressee &a, ContactListView* parent,
+ KABC::AddressBook *doc, const KABC::Field::List &fields );
+ const KABC::Addressee &addressee() const { return mAddressee; }
+ virtual void refresh();
+ virtual ContactListView* parent();
+ virtual QString key ( int, bool ) const;
+
+ /** Adds the border around the cell if the user wants it.
+ * This is how the single line config option is implemented.
+ */
+ virtual void paintCell(QPainter * p, const QColorGroup & cg,
+ int column, int width, int align );
+
+private:
+ KABC::Addressee mAddressee;
+ KABC::Field::List mFields;
+ ContactListView *parentListView;
+ KABC::AddressBook *mDocument;
+};
+
+
+/////////////////////////////////////////////
+// ContactListView
+
+class ContactListView : public KListView
+{
+ Q_OBJECT
+
+public:
+ ContactListView(KAddressBookTableView *view,
+ KABC::AddressBook *doc,
+ QWidget *parent,
+ const char *name = 0L );
+ virtual ~ContactListView() {}
+ //void resort();
+
+ /** Returns true if tooltips should be displayed, false otherwise
+ */
+ bool tooltips() const { return mToolTips; }
+ void setToolTipsEnabled(bool enabled) { mToolTips = enabled; }
+
+ bool alternateBackground() const { return mABackground; }
+ void setAlternateBackgroundEnabled(bool enabled);
+
+ bool singleLine() const { return mSingleLine; }
+ void setSingleLineEnabled(bool enabled) { mSingleLine = enabled; }
+
+ const QColor &alternateColor() const { return mAlternateColor; }
+
+ /** Sets the background pixmap to <i>filename</i>. If the
+ * QString is empty (QString::isEmpty()), then the background
+ * pixmap will be disabled.
+ */
+ void setBackgroundPixmap(const QString &filename);
+
+protected:
+ /** Paints the background pixmap in the empty area. This method is needed
+ * since Qt::FixedPixmap will not scroll with the list view.
+ */
+ virtual void paintEmptyArea( QPainter * p, const QRect & rect );
+ virtual void contentsMousePressEvent(QMouseEvent*);
+ void contentsMouseMoveEvent( QMouseEvent *e );
+ void contentsDropEvent( QDropEvent *e );
+ virtual bool acceptDrag(QDropEvent *e) const;
+
+protected slots:
+ void itemDropped(QDropEvent *e);
+
+public slots:
+
+signals:
+ void startAddresseeDrag();
+ void addresseeDropped(QDropEvent *);
+
+private:
+ KAddressBookTableView *pabWidget;
+ int oldColumn;
+ int column;
+ bool ascending;
+
+ bool mABackground;
+ bool mSingleLine;
+ bool mToolTips;
+
+ QColor mAlternateColor;
+
+ QPoint presspos;
+};
+
+
+#endif
diff --git a/kaddressbook/views/kaddressbookcardview.cpp b/kaddressbook/views/kaddressbookcardview.cpp
new file mode 100644
index 0000000..239429f
--- a/dev/null
+++ b/kaddressbook/views/kaddressbookcardview.cpp
@@ -0,0 +1,394 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include <qdragobject.h>
+#include <qevent.h>
+#include <qiconview.h>
+#include <qlayout.h>
+#include <qstringlist.h>
+
+#include <kabc/addressbook.h>
+#include <kabc/addressee.h>
+#include <kconfig.h>
+#include <kdebug.h>
+#include <klocale.h>
+
+#include "kabprefs.h"
+#include "viewmanager.h"
+
+#include "kaddressbookcardview.h"
+
+#ifndef KAB_EMBEDDED
+extern "C" {
+ void *init_libkaddrbk_cardview()
+ {
+ return ( new CardViewFactory );
+ }
+}
+#endif //KAB_EMBEDDED
+
+////////////////////////////////
+// AddresseeCardViewItem (internal class)
+class AddresseeCardViewItem : public CardViewItem
+{
+ public:
+ AddresseeCardViewItem(const KABC::Field::List &fields,
+ bool showEmptyFields,
+ KABC::AddressBook *doc, const KABC::Addressee &a,
+ CardView *parent)
+ : CardViewItem(parent, a.formattedName()),
+ mFields( fields ), mShowEmptyFields(showEmptyFields),
+ mDocument(doc), mAddressee(a)
+ {
+ if ( mFields.isEmpty() ) {
+ mFields = KABC::Field::defaultFields();
+ }
+ refresh();
+ }
+
+ const KABC::Addressee &addressee() const { return mAddressee; }
+
+ void refresh()
+ {
+ // Update our addressee, since it may have changed elsewhere
+ mAddressee = mDocument->findByUid(mAddressee.uid());
+
+ if (!mAddressee.isEmpty())
+ {
+ clearFields();
+
+ // Try all the selected fields until we find one with text.
+ // This will limit the number of unlabeled icons in the view
+ KABC::Field::List::Iterator iter;
+ for (iter = mFields.begin(); iter != mFields.end(); ++iter)
+ {
+ // insert empty fields or not? not doing so saves a bit of memory and CPU
+ // (during geometry calculations), but prevents having equally
+ // wide label columns in all cards, unless CardViewItem/CardView search
+ // globally for the widest label. (anders)
+ //if (mShowEmptyFields || !(*iter)->value( mAddressee ).isEmpty())
+ insertField((*iter)->label(), (*iter)->value( mAddressee ));
+ }
+
+ // We might want to make this the first field. hmm... -mpilone
+ setCaption( mAddressee.realName() );
+ }
+ }
+
+ private:
+ KABC::Field::List mFields;
+ bool mShowEmptyFields;
+ KABC::AddressBook *mDocument;
+ KABC::Addressee mAddressee;
+};
+
+///////////////////////////////
+// AddresseeCardView
+
+AddresseeCardView::AddresseeCardView(QWidget *parent, const char *name)
+ : CardView(parent, name)
+{
+ setAcceptDrops(true);
+}
+
+AddresseeCardView::~AddresseeCardView()
+{
+}
+
+void AddresseeCardView::dragEnterEvent(QDragEnterEvent *e)
+{
+#ifndef KAB_EMBEDDED
+ if (QTextDrag::canDecode(e))
+ e->accept();
+#else //KAB_EMBEDDED
+qDebug("AddresseeCardView::dragEnterEvent drag&drop is not implemented");
+#endif //KAB_EMBEDDED
+}
+
+void AddresseeCardView::dropEvent(QDropEvent *e)
+{
+ emit addresseeDropped(e);
+}
+
+void AddresseeCardView::startDrag()
+{
+ emit startAddresseeDrag();
+}
+
+
+///////////////////////////////
+// KAddressBookCardView
+
+KAddressBookCardView::KAddressBookCardView( KABC::AddressBook *ab,
+ QWidget *parent, const char *name )
+ : KAddressBookView( ab, parent, name )
+{
+ mShowEmptyFields = false;
+
+ // Init the GUI
+ QVBoxLayout *layout = new QVBoxLayout(viewWidget());
+
+ mCardView = new AddresseeCardView(viewWidget(), "mCardView");
+ mCardView->setSelectionMode(CardView::Extended);
+ layout->addWidget(mCardView);
+
+ // Connect up the signals
+ connect(mCardView, SIGNAL(executed(CardViewItem *)),
+ this, SLOT(addresseeExecuted(CardViewItem *)));
+ connect(mCardView, SIGNAL(selectionChanged()),
+ this, SLOT(addresseeSelected()));
+ connect(mCardView, SIGNAL(addresseeDropped(QDropEvent*)),
+ this, SIGNAL(dropped(QDropEvent*)));
+ connect(mCardView, SIGNAL(startAddresseeDrag()),
+ this, SIGNAL(startDrag()));
+}
+
+KAddressBookCardView::~KAddressBookCardView()
+{
+}
+
+void KAddressBookCardView::readConfig(KConfig *config)
+{
+ KAddressBookView::readConfig(config);
+
+ // costum colors?
+ if ( config->readBoolEntry( "EnableCustomColors", false ) )
+ {
+ QPalette p( mCardView->palette() );
+ QColor c = p.color(QPalette::Normal, QColorGroup::Base );
+ p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) );
+ c = p.color(QPalette::Normal, QColorGroup::Text );
+ p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) );
+ c = p.color(QPalette::Normal, QColorGroup::Button );
+ p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) );
+ c = p.color(QPalette::Normal, QColorGroup::ButtonText );
+ p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) );
+ c = p.color(QPalette::Normal, QColorGroup::Highlight );
+ p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) );
+ c = p.color(QPalette::Normal, QColorGroup::HighlightedText );
+ p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) );
+ mCardView->viewport()->setPalette( p );
+ }
+ else
+ {
+ // needed if turned off during a session.
+ mCardView->viewport()->setPalette( mCardView->palette() );
+ }
+
+ //custom fonts?
+ QFont f( font() );
+ if ( config->readBoolEntry( "EnableCustomFonts", false ) )
+ {
+ mCardView->setFont( config->readFontEntry( "TextFont", &f) );
+ f.setBold( true );
+ mCardView->setHeaderFont( config->readFontEntry( "HeaderFont", &f ) );
+ }
+ else
+ {
+ mCardView->setFont( f );
+ f.setBold( true );
+ mCardView->setHeaderFont( f );
+ }
+
+ mCardView->setDrawCardBorder(config->readBoolEntry("DrawBorder", true));
+ mCardView->setDrawColSeparators(config->readBoolEntry("DrawSeparators",
+ true));
+ mCardView->setDrawFieldLabels(config->readBoolEntry("DrawFieldLabels",false));
+ mShowEmptyFields = config->readBoolEntry("ShowEmptyFields", false);
+
+ mCardView->setShowEmptyFields( mShowEmptyFields );
+
+ mCardView->setItemWidth( config->readNumEntry( "ItemWidth", 200 ) );
+ mCardView->setItemMargin( config->readNumEntry( "ItemMargin", 0 ) );
+ mCardView->setItemSpacing( config->readNumEntry( "ItemSpacing", 10 ) );
+ mCardView->setSeparatorWidth( config->readNumEntry( "SeparatorWidth", 2 ) );
+
+ disconnect(mCardView, SIGNAL(executed(CardViewItem *)),
+ this, SLOT(addresseeExecuted(CardViewItem *)));
+
+ if (KABPrefs::instance()->mHonorSingleClick)
+ connect(mCardView, SIGNAL(executed(CardViewItem *)),
+ this, SLOT(addresseeExecuted(CardViewItem *)));
+ else
+ connect(mCardView, SIGNAL(doubleClicked(CardViewItem *)),
+ this, SLOT(addresseeExecuted(CardViewItem *)));
+
+}
+
+void KAddressBookCardView::writeConfig( KConfig *config )
+{
+ config->writeEntry( "ItemWidth", mCardView->itemWidth() );
+ KAddressBookView::writeConfig( config );
+}
+
+QStringList KAddressBookCardView::selectedUids()
+{
+ QStringList uidList;
+ CardViewItem *item;
+ AddresseeCardViewItem *aItem;
+
+ for (item = mCardView->firstItem(); item; item = item->nextItem())
+ {
+ if (item->isSelected())
+ {
+#ifndef KAB_EMBEDDED
+ aItem = dynamic_cast<AddresseeCardViewItem*>(item);
+#else //KAB_EMBEDDED
+ aItem = (AddresseeCardViewItem*)(item);
+#endif //KAB_EMBEDDED
+ if (aItem)
+ uidList << aItem->addressee().uid();
+ }
+ }
+
+ return uidList;
+}
+
+void KAddressBookCardView::refresh(QString uid)
+{
+ CardViewItem *item;
+ AddresseeCardViewItem *aItem;
+
+ if (uid.isNull())
+ {
+ // Rebuild the view
+ mCardView->viewport()->setUpdatesEnabled( false );
+ mCardView->clear();
+
+ KABC::Addressee::List addresseeList = addressees();
+ KABC::Addressee::List::Iterator iter;
+ for (iter = addresseeList.begin(); iter != addresseeList.end(); ++iter)
+ {
+ aItem = new AddresseeCardViewItem(fields(), mShowEmptyFields,
+ addressBook(), *iter, mCardView);
+ }
+ mCardView->viewport()->setUpdatesEnabled( true );
+ mCardView->viewport()->update();
+
+ // by default nothing is selected
+ emit selected(QString::null);
+ }
+ else
+ {
+ // Try to find the one to refresh
+ bool found = false;
+ for (item = mCardView->firstItem(); item && !found;
+ item = item->nextItem())
+ {
+#ifndef KAB_EMBEDDED
+ aItem = dynamic_cast<AddresseeCardViewItem*>(item);
+#else //KAB_EMBEDDED
+ aItem = (AddresseeCardViewItem*)(item);
+#endif //KAB_EMBEDDED
+
+ if ((aItem) && (aItem->addressee().uid() == uid))
+ {
+ aItem->refresh();
+ found = true;
+ }
+ }
+ }
+}
+
+void KAddressBookCardView::setSelected(QString uid, bool selected)
+{
+ CardViewItem *item;
+ AddresseeCardViewItem *aItem;
+
+ if (uid.isNull())
+ {
+ mCardView->selectAll(selected);
+ }
+ else
+ {
+ bool found = false;
+ for (item = mCardView->firstItem(); item && !found;
+ item = item->nextItem())
+ {
+#ifndef KAB_EMBEDDED
+ aItem = dynamic_cast<AddresseeCardViewItem*>(item);
+#else //KAB_EMBEDDED
+ aItem = (AddresseeCardViewItem*)(item);
+#endif //KAB_EMBEDDED
+
+ if ((aItem) && (aItem->addressee().uid() == uid))
+ {
+ mCardView->setSelected(aItem, selected);
+ mCardView->ensureItemVisible(item);
+ found = true;
+ }
+ }
+ }
+}
+
+//US added an additional method without parameter
+void KAddressBookCardView::setSelected()
+{
+ setSelected(QString::null, true);
+}
+
+void KAddressBookCardView::addresseeExecuted(CardViewItem *item)
+{
+#ifndef KAB_EMBEDDED
+ AddresseeCardViewItem *aItem = dynamic_cast<AddresseeCardViewItem*>(item);
+#else //KAB_EMBEDDED
+ AddresseeCardViewItem *aItem = (AddresseeCardViewItem*)(item);
+#endif //KAB_EMBEDDED
+ if (aItem)
+ {
+ //kdDebug()<<"... even has a valid item:)"<<endl;
+ emit executed(aItem->addressee().uid());
+ }
+}
+
+void KAddressBookCardView::addresseeSelected()
+{
+ CardViewItem *item;
+ AddresseeCardViewItem *aItem;
+
+ bool found = false;
+ for (item = mCardView->firstItem(); item && !found;
+ item = item->nextItem())
+ {
+ if (item->isSelected())
+ {
+#ifndef KAB_EMBEDDED
+ aItem = dynamic_cast<AddresseeCardViewItem*>(item);
+#else //KAB_EMBEDDED
+ aItem = (AddresseeCardViewItem*)(item);
+#endif //KAB_EMBEDDED
+ if ( aItem )
+ {
+ emit selected(aItem->addressee().uid());
+ found = true;
+ }
+ }
+ }
+
+ if (!found)
+ emit selected(QString::null);
+
+}
+#ifndef KAB_EMBEDDED
+#include "kaddressbookcardview.moc"
+#endif //KAB_EMBEDDED
diff --git a/kaddressbook/views/kaddressbookcardview.h b/kaddressbook/views/kaddressbookcardview.h
new file mode 100644
index 0000000..cd70371
--- a/dev/null
+++ b/kaddressbook/views/kaddressbookcardview.h
@@ -0,0 +1,117 @@
+#ifndef KADDRESSBOOKCARDVIEW_H
+#define KADDRESSBOOKCARDVIEW_H
+
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include <qstring.h>
+#ifndef KAB_EMBEDDED
+#include <kiconview.h>
+#else //KAB_EMBEDDED
+#include <klocale.h>
+#endif //KAB_EMBEDDED
+
+#include "cardview.h"
+#include "kaddressbookview.h"
+#include "configurecardviewdialog.h"
+
+class QDragEnterEvent;
+class QDragEntryEvent;
+class QDropEvent;
+class KConfig;
+class AddresseeCardView;
+
+/**
+ This view uses the CardView class to create a card view. At some
+ point in the future I think this will be the default view of
+ KAddressBook.
+ */
+class KAddressBookCardView : public KAddressBookView
+{
+ Q_OBJECT
+
+ public:
+ KAddressBookCardView( KABC::AddressBook *ab, QWidget *parent,
+ const char *name = 0 );
+ virtual ~KAddressBookCardView();
+
+ virtual QStringList selectedUids();
+ virtual QString type() const { return "Card"; }
+
+ virtual void readConfig(KConfig *config);
+ virtual void writeConfig(KConfig *);
+
+ public slots:
+ void refresh(QString uid = QString::null);
+ void setSelected(QString uid/*US = QString::null*/, bool selected/*US = true*/);
+//US added an additional method without parameter
+ void setSelected();
+
+ protected slots:
+ void addresseeExecuted(CardViewItem *item);
+ void addresseeSelected();
+
+ private:
+ AddresseeCardView *mCardView;
+ bool mShowEmptyFields;
+};
+
+class AddresseeCardView : public CardView
+{
+ Q_OBJECT
+ public:
+ AddresseeCardView(QWidget *parent, const char *name = 0);
+ ~AddresseeCardView();
+
+ signals:
+ void startAddresseeDrag();
+ void addresseeDropped(QDropEvent *);
+
+ protected:
+ virtual void dragEnterEvent(QDragEnterEvent *);
+ virtual void dropEvent(QDropEvent *);
+ virtual void startDrag();
+};
+
+
+class CardViewFactory : public ViewFactory
+{
+ public:
+ KAddressBookView *view( KABC::AddressBook *ab, QWidget *parent, const char *name )
+ {
+ return new KAddressBookCardView( ab, parent, name );
+ }
+
+ QString type() const { return "Card"; }
+
+ QString description() const { return i18n( "Rolodex style cards represent contacts." ); }
+
+ ViewConfigureWidget *configureWidget( KABC::AddressBook *ab, QWidget *parent,
+ const char *name = 0 )
+ {
+ return new ConfigureCardViewWidget( ab, parent, name );
+ }
+};
+
+
+#endif
diff --git a/kaddressbook/views/kaddressbookiconview.cpp b/kaddressbook/views/kaddressbookiconview.cpp
new file mode 100644
index 0000000..50ff285
--- a/dev/null
+++ b/kaddressbook/views/kaddressbookiconview.cpp
@@ -0,0 +1,378 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef KAB_EMBEDDED
+#include <qiconview.h>
+#include <qstringlist.h>
+
+#include <kabc/addressee.h>
+#include <kconfig.h>
+#include <kdebug.h>
+#include <kglobal.h>
+#include <kiconloader.h>
+#include <klocale.h>
+
+#else //KAB_EMBEDDED
+#endif //KAB_EMBEDDED
+
+#include <kabc/addressbook.h>
+#include "kabprefs.h"
+#include "viewmanager.h"
+#include "kaddressbookiconview.h"
+#include <qlayout.h>
+#include <kglobal.h>
+/*US transfered to the headerfile
+class IconViewFactory : public ViewFactory
+{
+ public:
+ KAddressBookView *view( KABC::AddressBook *ab, QWidget *parent, const char *name )
+ {
+ return new KAddressBookIconView( ab, parent, name );
+ }
+
+ QString type() const { return "Icon"; }
+
+ QString description() const { return i18n( "Icons represent contacts. Very simple view." ); }
+};
+
+*/
+
+extern "C" {
+ void *init_libkaddrbk_iconview()
+ {
+ return ( new IconViewFactory );
+ }
+}
+
+////////////////////////////////
+// AddresseeIconView (internal class)
+#ifndef KAB_EMBEDDED
+AddresseeIconView::AddresseeIconView(QWidget *parent, const char *name)
+ : KIconView(parent, name)
+#else //KAB_EMBEDDED
+AddresseeIconView::AddresseeIconView(QWidget *parent, const char *name)
+ : QIconView(parent, name)
+#endif //KAB_EMBEDDED
+
+{
+ setSelectionMode( QIconView::Extended );
+ setResizeMode( QIconView::Adjust );
+ setWordWrapIconText( true );
+ setGridX( 100 );
+ setItemsMovable(false);
+ setSorting(true, true);
+
+
+//US ??? setMode( KIconView::Select );
+
+#ifndef KAB_EMBEDDED
+
+ connect(this, SIGNAL(dropped(QDropEvent*, const QValueList<QIconDragItem>&)),
+ this, SLOT(itemDropped(QDropEvent*, const QValueList<QIconDragItem>&)));
+#endif //KAB_EMBEDDED
+}
+
+AddresseeIconView::~AddresseeIconView()
+{
+}
+
+void AddresseeIconView::itemDropped(QDropEvent *e,
+ const QValueList<QIconDragItem> &)
+{
+ emit addresseeDropped(e);
+}
+
+QDragObject *AddresseeIconView::dragObject()
+{
+ emit startAddresseeDrag();
+
+ // We never want IconView to start the drag
+ return 0;
+}
+////////////////////////////////
+// AddresseeIconViewItem (internal class)
+#ifndef KAB_EMBEDDED
+class AddresseeIconViewItem : public KIconViewItem
+#else //KAB_EMBEDDED
+class AddresseeIconViewItem : public QIconViewItem
+#endif //KAB_EMBEDDED
+{
+ public:
+#ifndef KAB_EMBEDDED
+ AddresseeIconViewItem(const KABC::Field::List &fields,
+ KABC::AddressBook *doc, const KABC::Addressee &a,
+ QIconView *parent)
+ : KIconViewItem(parent), mFields( fields ), mDocument(doc), mAddressee(a)
+#else //KAB_EMBEDDED
+ AddresseeIconViewItem(const KABC::Field::List &fields,
+ KABC::AddressBook *doc, const KABC::Addressee &a,
+ QIconView *parent)
+ : QIconViewItem(parent), mFields( fields ), mDocument(doc), mAddressee(a)
+#endif //KAB_EMBEDDED
+ {
+ if ( mFields.isEmpty() ) {
+ mFields = KABC::Field::defaultFields();
+ }
+ refresh();
+ }
+
+ const KABC::Addressee &addressee() const { return mAddressee; }
+
+ void refresh()
+ {
+ // Update our addressee, since it may have changed elsewhere
+ mAddressee = mDocument->findByUid(mAddressee.uid());
+
+ if (!mAddressee.isEmpty())
+ setText( mAddressee.givenName() + " " + mAddressee.familyName() );
+
+ QPixmap icon;
+ QPixmap defaultIcon( KGlobal::iconLoader()->loadIcon( "vcard", KIcon::Desktop, 128 ) );
+ KABC::Picture pic = mAddressee.photo();
+ if ( pic.data().isNull() )
+ pic = mAddressee.logo();
+
+ if ( pic.isIntern() && !pic.data().isNull() ) {
+ QImage img = pic.data();
+#ifndef KAB_EMBEDDED
+ if ( img.width() > img.height() )
+ icon = img.scaleWidth( 32 );
+ else
+ icon = img.scaleHeight( 32 );
+#else //KAB_EMBEDDED
+ qDebug("AddresseeIconViewItem::refresh - scale here dependend of the displaysize and the right factor");
+ icon.convertFromImage(img.smoothScale(32, 32));
+#endif //KAB_EMBEDDED
+
+ } else
+ icon = defaultIcon;
+
+ setPixmap( icon );
+ }
+
+ private:
+ KABC::Field::List mFields;
+ KABC::AddressBook *mDocument;
+ KABC::Addressee mAddressee;
+};
+
+///////////////////////////////
+// KAddressBookView
+
+KAddressBookIconView::KAddressBookIconView( KABC::AddressBook *ab,
+ QWidget *parent, const char *name)
+ : KAddressBookView( ab, parent, name )
+{
+ // Init the GUI
+ QVBoxLayout *layout = new QVBoxLayout(viewWidget());
+
+ mIconView = new AddresseeIconView(viewWidget(), "mIconView");
+ layout->addWidget(mIconView);
+
+ // Connect up the signals
+
+//US method executed is part of KIconView
+//US connect(mIconView, SIGNAL(executed(QIconViewItem *)),
+//US this, SLOT(addresseeExecuted(QIconViewItem *)));
+ connect(mIconView, SIGNAL(selectionChanged(QIconViewItem *)),
+ this, SLOT(addresseeExecuted(QIconViewItem *)));
+
+ connect(mIconView, SIGNAL(selectionChanged()),
+ this, SLOT(addresseeSelected()));
+ connect(mIconView, SIGNAL(addresseeDropped(QDropEvent*)),
+ this, SIGNAL(dropped(QDropEvent*)));
+ connect(mIconView, SIGNAL(startAddresseeDrag()),
+ this, SIGNAL(startDrag()));
+}
+
+KAddressBookIconView::~KAddressBookIconView()
+{
+}
+
+void KAddressBookIconView::readConfig(KConfig *config)
+{
+ KAddressBookView::readConfig(config);
+
+//US method executed is part of KIconView
+//US disconnect(mIconView, SIGNAL(executed(QIconViewItem *)),
+//US this, SLOT(addresseeExecuted(QIconViewItem *)));
+ disconnect(mIconView, SIGNAL(selectionChanged(QIconViewItem *)),
+ this, SLOT(addresseeExecuted(QIconViewItem *)));
+
+//US method executed is part of KIconView. Use selectionChanged instead
+/*US
+ if (KABPrefs::instance()->mHonorSingleClick)
+ connect(mIconView, SIGNAL(executed(QIconViewItem *)),
+ this, SLOT(addresseeExecuted(QIconViewItem *)));
+ else
+ connect(mIconView, SIGNAL(doubleClicked(QIconViewItem *)),
+ this, SLOT(addresseeExecuted(QIconViewItem *)));
+*/
+ connect(mIconView, SIGNAL(selectionChanged(QIconViewItem *)),
+ this, SLOT(addresseeExecuted(QIconViewItem *)));
+
+}
+
+QStringList KAddressBookIconView::selectedUids()
+{
+ QStringList uidList;
+ QIconViewItem *item;
+ AddresseeIconViewItem *aItem;
+
+ for (item = mIconView->firstItem(); item; item = item->nextItem())
+ {
+ if (item->isSelected())
+ {
+#ifndef KAB_EMBEDDED
+ aItem = dynamic_cast<AddresseeIconViewItem*>(item);
+#else //KAB_EMBEDDED
+ aItem = (AddresseeIconViewItem*)(item);
+#endif //KAB_EMBEDDED
+ if (aItem)
+ uidList << aItem->addressee().uid();
+ }
+ }
+
+ return uidList;
+}
+
+void KAddressBookIconView::refresh(QString uid)
+{
+ QIconViewItem *item;
+ AddresseeIconViewItem *aItem;
+
+ if ( uid.isNull() ) {
+ // Rebuild the view
+ mIconView->clear();
+ mIconList.clear();
+
+ KABC::Addressee::List addresseeList = addressees();
+ KABC::Addressee::List::Iterator iter;
+ for ( iter = addresseeList.begin(); iter != addresseeList.end(); ++iter )
+ aItem = new AddresseeIconViewItem( fields(), addressBook(), *iter, mIconView );
+
+ mIconView->arrangeItemsInGrid( true );
+
+ for ( item = mIconView->firstItem(); item; item = item->nextItem() )
+ {
+#ifndef KAB_EMBEDDED
+ AddresseeIconViewItem* aivi = dynamic_cast<AddresseeIconViewItem*>( item );
+#else //KAB_EMBEDDED
+ AddresseeIconViewItem* aivi = (AddresseeIconViewItem*)( item );
+#endif //KAB_EMBEDDED
+ mIconList.append( aivi );
+ }
+
+ } else {
+ // Try to find the one to refresh
+ for ( item = mIconView->firstItem(); item; item = item->nextItem() ) {
+#ifndef KAB_EMBEDDED
+ aItem = dynamic_cast<AddresseeIconViewItem*>(item);
+#else //KAB_EMBEDDED
+ aItem = (AddresseeIconViewItem*)(item);
+#endif //KAB_EMBEDDED
+ if ((aItem) && (aItem->addressee().uid() == uid)) {
+ aItem->refresh();
+ mIconView->arrangeItemsInGrid( true );
+ return;
+ }
+ }
+ refresh( QString::null );
+ }
+}
+
+void KAddressBookIconView::setSelected(QString uid, bool selected)
+{
+ QIconViewItem *item;
+ AddresseeIconViewItem *aItem;
+
+ if (uid.isNull())
+ {
+ mIconView->selectAll(selected);
+ }
+ else
+ {
+ bool found = false;
+ for (item = mIconView->firstItem(); item && !found;
+ item = item->nextItem())
+ {
+#ifndef KAB_EMBEDDED
+ aItem = dynamic_cast<AddresseeIconViewItem*>(item);
+#else //KAB_EMBEDDED
+ aItem = (AddresseeIconViewItem*)(item);
+#endif //KAB_EMBEDDED
+
+ if ((aItem) && (aItem->addressee().uid() == uid))
+ {
+ mIconView->setSelected(aItem, selected);
+ mIconView->ensureItemVisible( aItem );
+ found = true;
+ }
+ }
+ }
+}
+
+void KAddressBookIconView::addresseeExecuted(QIconViewItem *item)
+{
+#ifndef KAB_EMBEDDED
+ AddresseeIconViewItem *aItem = dynamic_cast<AddresseeIconViewItem*>(item);
+#else //KAB_EMBEDDED
+ AddresseeIconViewItem *aItem = (AddresseeIconViewItem*)(item);
+#endif //KAB_EMBEDDED
+
+ if (aItem) {
+ emit executed(aItem->addressee().uid());
+ }
+}
+
+void KAddressBookIconView::addresseeSelected()
+{
+ QIconViewItem *item;
+ AddresseeIconViewItem *aItem;
+
+ bool found = false;
+ for (item = mIconView->firstItem(); item && !found;
+ item = item->nextItem())
+ {
+ if (item->isSelected())
+ {
+#ifndef KAB_EMBEDDED
+ aItem = dynamic_cast<AddresseeIconViewItem*>(item);
+#else //KAB_EMBEDDED
+ aItem = (AddresseeIconViewItem*)(item);
+#endif //KAB_EMBEDDED
+ if (aItem)
+ {
+ emit selected(aItem->addressee().uid());
+ found = true;
+ }
+ }
+ }
+
+ if (!found)
+ emit selected(QString::null);
+}
+
+#ifndef KAB_EMBEDDED
+#include "kaddressbookiconview.moc"
+#endif //KAB_EMBEDDED
diff --git a/kaddressbook/views/kaddressbookiconview.h b/kaddressbook/views/kaddressbookiconview.h
new file mode 100644
index 0000000..3afada3
--- a/dev/null
+++ b/kaddressbook/views/kaddressbookiconview.h
@@ -0,0 +1,130 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef KADDRESSBOOKICONVIEW_H
+#define KADDRESSBOOKICONVIEW_H
+
+#include <qstring.h>
+#ifndef KAB_EMBEDDED
+#include <kiconview.h>
+#else //KAB_EMBEDDED
+#include <qiconview.h>
+#include <qptrlist.h>
+#include <klocale.h>
+#endif //KAB_EMBEDDED
+#include "kaddressbookview.h"
+
+class QIconViewItem;
+class KConfig;
+class AddresseeIconView;
+class AddresseeIconViewItem;
+class QIconDragItem;
+class KAddressBookIconView;
+
+namespace KABC { class AddressBook; }
+
+/** This is an example kaddressbook view that is implemented using
+* KIconView. This view is not the most useful view, but it displays
+* how simple implementing a new view can be.
+*/
+class KAddressBookIconView : public KAddressBookView
+{
+ Q_OBJECT
+
+ public:
+ KAddressBookIconView( KABC::AddressBook *ab, QWidget *parent,
+ const char *name = 0 );
+ virtual ~KAddressBookIconView();
+
+ virtual QStringList selectedUids();
+ virtual QString type() const { return "Icon"; }
+
+ virtual void readConfig(KConfig *config);
+
+ public slots:
+ void refresh(QString uid = QString::null);
+#ifndef KAB_EMBEDDED
+//MOC_SKIP_BEGIN
+ void setSelected(QString uid = QString::null, bool selected = true);
+//MOC_SKIP_END
+#else //KAB_EMBEDDED
+//US my MOC do not like default parameters ???
+ void setSelected(QString uid, bool selected);
+#endif //KAB_EMBEDDED
+
+ protected slots:
+ void addresseeExecuted(QIconViewItem *item);
+ void addresseeSelected();
+
+ private:
+ AddresseeIconView *mIconView;
+ QPtrList<AddresseeIconViewItem> mIconList;
+};
+
+
+#ifndef KAB_EMBEDDED
+//MOC_SKIP_BEGIN
+class AddresseeIconView : public KIconView
+//MOC_SKIP_END
+#else //KAB_EMBEDDED
+class AddresseeIconView : public QIconView
+#endif //KAB_EMBEDDED
+{
+ Q_OBJECT
+
+ public:
+ AddresseeIconView(QWidget *parent, const char *name);
+ ~AddresseeIconView();
+
+ signals:
+ void addresseeDropped(QDropEvent *);
+ void startAddresseeDrag();
+
+ protected:
+ virtual QDragObject *dragObject();
+
+ protected slots:
+ void itemDropped(QDropEvent *, const QValueList<QIconDragItem> &);
+};
+
+class IconViewFactory : public ViewFactory
+{
+ public:
+ KAddressBookView *view( KABC::AddressBook *ab, QWidget *parent, const char *name )
+ {
+ return new KAddressBookIconView( ab, parent, name );
+ }
+
+ QString type() const { return "Icon"; }
+
+ QString description() const { return i18n( "Icons represent contacts. Very simple view." ); }
+};
+/*
+extern "C" {
+ void *init_libkaddrbk_iconview()
+ {
+ return ( new IconViewFactory );
+ }
+}
+*/
+#endif
diff --git a/kaddressbook/views/kaddressbooktableview.cpp b/kaddressbook/views/kaddressbooktableview.cpp
new file mode 100644
index 0000000..ee2fcf8
--- a/dev/null
+++ b/kaddressbook/views/kaddressbooktableview.cpp
@@ -0,0 +1,337 @@
+// $Id$
+
+#include <qvbox.h>
+#include <qlistbox.h>
+#include <qwidget.h>
+#include <qfile.h>
+#include <qimage.h>
+#include <qcombobox.h>
+#include <qapplication.h>
+#include <qdragobject.h>
+#include <qevent.h>
+#include <qurl.h>
+#include <qpixmap.h>
+
+#include <kabc/addressbook.h>
+#include <kapplication.h>
+#include <kconfig.h>
+#include <kcolorbutton.h>
+#include <kdebug.h>
+#include <kglobal.h>
+#include <kiconloader.h>
+#include <klineedit.h>
+#include <klocale.h>
+#include <kmessagebox.h>
+#include <kurl.h>
+#include <kurlrequester.h>
+
+//US#include "configuretableviewdialog.h"
+#include "contactlistview.h"
+#include "kabprefs.h"
+#include "undocmds.h"
+#include "viewmanager.h"
+
+#include <qlayout.h>
+
+
+#include "kaddressbooktableview.h"
+
+
+KAddressBookTableView::KAddressBookTableView( KABC::AddressBook *ab,
+ QWidget *parent, const char *name )
+ : KAddressBookView( ab, parent, name )
+{
+ mainLayout = new QVBoxLayout( viewWidget(), 2 );
+
+ // The list view will be created when the config is read.
+ mListView = 0;
+}
+
+KAddressBookTableView::~KAddressBookTableView()
+{
+}
+
+void KAddressBookTableView::reconstructListView()
+{
+ if (mListView)
+ {
+ disconnect(mListView, SIGNAL(selectionChanged()),
+ this, SLOT(addresseeSelected()));
+ disconnect(mListView, SIGNAL(executed(QListViewItem*)),
+ this, SLOT(addresseeExecuted(QListViewItem*)));
+ disconnect(mListView, SIGNAL(doubleClicked(QListViewItem*)),
+ this, SLOT(addresseeExecuted(QListViewItem*)));
+ disconnect(mListView, SIGNAL(startAddresseeDrag()), this,
+ SIGNAL(startDrag()));
+ disconnect(mListView, SIGNAL(returnPressed(QListViewItem*)),
+ this, SLOT(addresseeExecuted(QListViewItem*)));
+
+ disconnect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this,
+ SIGNAL(dropped(QDropEvent*)));
+ delete mListView;
+ }
+
+ mListView = new ContactListView( this, addressBook(), viewWidget() );
+
+ // Add the columns
+ KABC::Field::List fieldList = fields();
+ KABC::Field::List::ConstIterator it;
+
+ int c = 0;
+ for( it = fieldList.begin(); it != fieldList.end(); ++it ) {
+ mListView->addColumn( (*it)->label() );
+ mListView->setColumnWidthMode(c++, QListView::Manual);
+//US
+ // qDebug("KAddressBookTableView::reconstructListView: field %s", (*it)->label().latin1());
+ }
+
+ connect(mListView, SIGNAL(selectionChanged()),
+ this, SLOT(addresseeSelected()));
+ connect(mListView, SIGNAL(startAddresseeDrag()), this,
+ SIGNAL(startDrag()));
+ connect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this,
+ SIGNAL(dropped(QDropEvent*)));
+
+ if (KABPrefs::instance()->mHonorSingleClick)
+ connect(mListView, SIGNAL(executed(QListViewItem*)),
+ this, SLOT(addresseeExecuted(QListViewItem*)));
+ else
+ connect(mListView, SIGNAL(doubleClicked(QListViewItem*)),
+ this, SLOT(addresseeExecuted(QListViewItem*)));
+ connect(mListView, SIGNAL(returnPressed(QListViewItem*)),
+ this, SLOT(addresseeExecuted(QListViewItem*)));
+ connect(mListView, SIGNAL(signalDelete()),
+ this, SLOT(addresseeDeleted()));
+
+ refresh();
+
+ mListView->setSorting( 0, true );
+ mainLayout->addWidget( mListView );
+ mainLayout->activate();
+ mListView->show();
+}
+
+void KAddressBookTableView::writeConfig(KConfig *config)
+{
+ KAddressBookView::writeConfig(config);
+
+ mListView->saveLayout(config, config->group());
+}
+
+void KAddressBookTableView::readConfig(KConfig *config)
+{
+ KAddressBookView::readConfig( config );
+
+ // The config could have changed the fields, so we need to reconstruct
+ // the listview.
+ reconstructListView();
+
+ // Set the list view options
+ mListView->setAlternateBackgroundEnabled(config->readBoolEntry("ABackground",
+ true));
+ mListView->setSingleLineEnabled(config->readBoolEntry("SingleLine", false));
+ mListView->setToolTipsEnabled(config->readBoolEntry("ToolTips", true));
+
+ if (config->readBoolEntry("Background", false))
+ mListView->setBackgroundPixmap(config->readEntry("BackgroundName"));
+
+ // Restore the layout of the listview
+ mListView->restoreLayout(config, config->group());
+}
+
+void KAddressBookTableView::refresh(QString uid)
+{
+ // For now just repopulate. In reality this method should
+ // check the value of uid, and if valid iterate through
+ // the listview to find the entry, then tell it to refresh.
+
+ if (uid.isNull()) {
+ // Clear the list view
+ QString currentUID, nextUID;
+#ifndef KAB_EMBEDDED
+ ContactListViewItem *currentItem = dynamic_cast<ContactListViewItem*>( mListView->currentItem() );
+#else //KAB_EMBEDDED
+ ContactListViewItem *currentItem = (ContactListViewItem*)( mListView->currentItem() );
+#endif //KAB_EMBEDDED
+
+ if ( currentItem ) {
+#ifndef KAB_EMBEDDED
+ ContactListViewItem *nextItem = dynamic_cast<ContactListViewItem*>( currentItem->itemBelow() );
+#else //KAB_EMBEDDED
+ ContactListViewItem *nextItem = (ContactListViewItem*)( currentItem->itemBelow() );
+#endif //KAB_EMBEDDED
+ if ( nextItem )
+ nextUID = nextItem->addressee().uid();
+ currentUID = currentItem->addressee().uid();
+ }
+
+ mListView->clear();
+
+ currentItem = 0;
+ KABC::Addressee::List addresseeList = addressees();
+ KABC::Addressee::List::Iterator it;
+ for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) {
+ ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields());
+ if ( (*it).uid() == currentUID )
+ currentItem = item;
+ else if ( (*it).uid() == nextUID && !currentItem )
+ currentItem = item;
+ }
+
+ // Sometimes the background pixmap gets messed up when we add lots
+ // of items.
+ mListView->repaint();
+
+ if ( currentItem ) {
+ mListView->setCurrentItem( currentItem );
+ mListView->ensureItemVisible( currentItem );
+ }
+ } else {
+ // Only need to update on entry. Iterate through and try to find it
+ ContactListViewItem *ceItem;
+ QListViewItemIterator it( mListView );
+ while ( it.current() ) {
+#ifndef KAB_EMBEDDED
+ ceItem = dynamic_cast<ContactListViewItem*>( it.current() );
+#else //KAB_EMBEDDED
+ ceItem = (ContactListViewItem*)( it.current() );
+#endif //KAB_EMBEDDED
+
+ if ( ceItem && ceItem->addressee().uid() == uid ) {
+ ceItem->refresh();
+ return;
+ }
+ ++it;
+ }
+
+ refresh( QString::null );
+ }
+}
+
+QStringList KAddressBookTableView::selectedUids()
+{
+ QStringList uidList;
+ QListViewItem *item;
+ ContactListViewItem *ceItem;
+
+ for(item = mListView->firstChild(); item; item = item->itemBelow())
+ {
+ if (mListView->isSelected( item ))
+ {
+#ifndef KAB_EMBEDDED
+ ceItem = dynamic_cast<ContactListViewItem*>(item);
+#else //KAB_EMBEDDED
+ ceItem = (ContactListViewItem*)(item);
+#endif //KAB_EMBEDDED
+
+ if (ceItem != 0L)
+ uidList << ceItem->addressee().uid();
+ }
+ }
+ if ( uidList.count() == 0 )
+ if ( mListView->currentItem() ) {
+ ceItem = (ContactListViewItem*)(mListView->currentItem()) ;
+ uidList << ceItem->addressee().uid();
+ }
+
+ return uidList;
+}
+
+void KAddressBookTableView::setSelected(QString uid, bool selected)
+{
+ QListViewItem *item;
+ ContactListViewItem *ceItem;
+
+ if (uid.isNull())
+ {
+ mListView->selectAll(selected);
+ }
+ else
+ {
+ for(item = mListView->firstChild(); item; item = item->itemBelow())
+ {
+#ifndef KAB_EMBEDDED
+ ceItem = dynamic_cast<ContactListViewItem*>(item);
+#else //KAB_EMBEDDED
+ ceItem = (ContactListViewItem*)(item);
+#endif //KAB_EMBEDDED
+
+
+ if ((ceItem != 0L) && (ceItem->addressee().uid() == uid))
+ {
+ mListView->setSelected(item, selected);
+
+ if (selected)
+ mListView->ensureItemVisible(item);
+ }
+ }
+ }
+}
+
+void KAddressBookTableView::addresseeSelected()
+{
+ // We need to try to find the first selected item. This might not be the
+ // last selected item, but when QListView is in multiselection mode,
+ // there is no way to figure out which one was
+ // selected last.
+ QListViewItem *item;
+ bool found =false;
+ for (item = mListView->firstChild(); item && !found;
+ item = item->nextSibling())
+ {
+ if (item->isSelected())
+ {
+ found = true;
+#ifndef KAB_EMBEDDED
+ ContactListViewItem *ceItem
+ = dynamic_cast<ContactListViewItem*>(item);
+#else //KAB_EMBEDDED
+ ContactListViewItem *ceItem
+ = (ContactListViewItem*)(item);
+#endif //KAB_EMBEDDED
+
+ if ( ceItem ) emit selected(ceItem->addressee().uid());
+ }
+ }
+
+ if (!found)
+ emit selected(QString::null);
+}
+
+void KAddressBookTableView::addresseeExecuted(QListViewItem *item)
+{
+ if (item)
+ {
+#ifndef KAB_EMBEDDED
+ ContactListViewItem *ceItem
+ = dynamic_cast<ContactListViewItem*>(item);
+#else //KAB_EMBEDDED
+ ContactListViewItem *ceItem
+ = (ContactListViewItem*)(item);
+#endif //KAB_EMBEDDED
+
+ if (ceItem)
+ {
+ emit executed(ceItem->addressee().uid());
+ }
+ }
+ else
+ {
+ emit executed(QString::null);
+ }
+}
+
+void KAddressBookTableView::addresseeDeleted()
+{
+
+ emit deleteRequest();
+
+}
+
+
+
+
+
+#ifndef KAB_EMBEDDED
+#include "kaddressbooktableview.moc"
+#endif //KAB_EMBEDDED
diff --git a/kaddressbook/views/kaddressbooktableview.h b/kaddressbook/views/kaddressbooktableview.h
new file mode 100644
index 0000000..bb991bc
--- a/dev/null
+++ b/kaddressbook/views/kaddressbooktableview.h
@@ -0,0 +1,114 @@
+#ifndef KADDRESSBOOKTABLEVIEW_H
+#define KADDRESSBOOKTABLEVIEW_H
+
+
+#ifndef KAB_EMBEDDED
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <qwidget.h>
+#include <qlistview.h>
+#include <qstring.h>
+#include <qdialog.h>
+#include <qtabdialog.h>
+#include <qstringlist.h>
+#include <qvaluelist.h>
+
+#include "undo.h"
+
+#else //KAB_EMBEDDED
+#include "views/configuretableviewdialog.h"
+#endif //KAB_EMBEDDED
+
+#include "klocale.h"
+#include "kaddressbookview.h"
+
+class QListViewItem;
+class QListBox;
+class QVBoxLayout;
+class KConfig;
+
+class ContactListViewItem;
+class ContactListView;
+
+
+namespace KABC { class AddressBook; }
+
+/**
+ * This class is the table view for kaddressbook. This view is a KListView
+ * with multiple columns for the selected fields.
+ *
+ * @short Table View
+ * @author Don Sanders <dsanders@kde.org>
+ * @version 0.1
+ */
+class KAddressBookTableView : public KAddressBookView
+{
+friend class ContactListView;
+
+ Q_OBJECT
+
+ public:
+ KAddressBookTableView( KABC::AddressBook *ab, QWidget *parent,
+ const char *name = 0 );
+ virtual ~KAddressBookTableView();
+
+ virtual void refresh(QString uid = QString::null);
+ virtual QStringList selectedUids();
+ virtual void setSelected(QString uid = QString::null, bool selected = false);
+ virtual void readConfig(KConfig *config);
+ virtual void writeConfig(KConfig *config);
+ virtual QString type() const { return "Table"; }
+
+ public slots:
+ virtual void reconstructListView();
+
+ protected slots:
+ /** Called whenever the user selects an addressee in the list view.
+ */
+ void addresseeSelected();
+ void addresseeDeleted();
+
+ /** Called whenever the user executes an addressee. In terms of the
+ * list view, this is probably a double click
+ */
+ void addresseeExecuted(QListViewItem*);
+
+ private:
+ QVBoxLayout *mainLayout;
+ ContactListView *mListView;
+};
+
+
+class TableViewFactory : public ViewFactory
+{
+ public:
+ KAddressBookView *view( KABC::AddressBook *ab, QWidget *parent, const char *name )
+ {
+ return new KAddressBookTableView( ab, parent, name );
+ }
+
+ QString type() const { return "Table"; }
+
+ QString description() const { return i18n( "A listing of contacts in a table. Each cell of "
+ "the table holds a field of the contact." ); }
+
+ ViewConfigureWidget *configureWidget( KABC::AddressBook *ab, QWidget *parent,
+ const char *name = 0 )
+ {
+ return new ConfigureTableViewWidget( ab, parent, name );
+ }
+};
+/*US
+extern "C" {
+ void *init_libkaddrbk_tableview()
+ {
+ return ( new TableViewFactory );
+ }
+}
+*/
+
+#endif
diff --git a/kaddressbook/xxport/csv_xxport.cpp b/kaddressbook/xxport/csv_xxport.cpp
new file mode 100644
index 0000000..ce35053
--- a/dev/null
+++ b/kaddressbook/xxport/csv_xxport.cpp
@@ -0,0 +1,187 @@
+/*
+ This file is part of KAddressbook.
+ Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+/*
+Enhanced Version of the file for platform independent KDE tools.
+Copyright (c) 2004 Ulf Schenk
+
+$Id$
+*/
+
+#include <qfile.h>
+#include <qregexp.h>
+#include <qtextstream.h>
+
+#include <kfiledialog.h>
+#ifndef KAB_EMBEDDED
+#include <kio/netaccess.h>
+#endif //KAB_EMBEDDED
+
+#include <klocale.h>
+#include <kmessagebox.h>
+#include <ktempfile.h>
+#include <kurl.h>
+
+#include "csvimportdialog.h"
+
+#include "csv_xxport.h"
+
+
+#ifndef KAB_EMBEDDED
+
+class CSVXXPortFactory : public XXPortFactory
+{
+ public:
+ XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name )
+ {
+ return new CSVXXPort( ab, parent, name );
+ }
+};
+
+
+extern "C"
+{
+ void *init_libkaddrbk_csv_xxport()
+ {
+ return ( new CSVXXPortFactory() );
+ }
+}
+#endif //KAB_EMBEDDED
+
+
+CSVXXPort::CSVXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name )
+ : XXPortObject( ab, parent, name )
+{
+ createImportAction( i18n( "Import CSV List..." ) );
+ createExportAction( i18n( "Export CSV List..." ) );
+}
+
+bool CSVXXPort::exportContacts( const KABC::AddresseeList &list, const QString& )
+{
+#ifndef KAB_EMBEDDED
+ KURL url = KFileDialog::getSaveURL( "addressbook.csv" );
+ if ( url.isEmpty() )
+ return true;
+
+ if ( !url.isLocalFile() ) {
+ KTempFile tmpFile;
+ if ( tmpFile.status() != 0 ) {
+ QString txt = i18n( "<qt>Unable to open file <b>%1</b>.%2.</qt>" );
+ KMessageBox::error( parentWidget(), txt.arg( url.url() )
+ .arg( strerror( tmpFile.status() ) ) );
+ return false;
+ }
+
+ doExport( tmpFile.file(), list );
+ tmpFile.close();
+
+ return KIO::NetAccess::upload( tmpFile.name(), url, parentWidget() );
+ } else {
+ QFile file( url.path() );
+ if ( !file.open( IO_WriteOnly ) ) {
+ QString txt = i18n( "<qt>Unable to open file <b>%1</b>.</qt>" );
+ KMessageBox::error( parentWidget(), txt.arg( url.path() ) );
+ return false;
+ }
+
+ doExport( &file, list );
+ file.close();
+
+ return true;
+ }
+
+#else //KAB_EMBEDDED
+
+ QString fileName = KFileDialog::getSaveFileName( "addressbook.csv", i18n("Save file"), parentWidget() );
+
+ if ( fileName.isEmpty() )
+ return true;
+
+ QFile file( fileName );
+ if ( !file.open( IO_WriteOnly ) ) {
+ QString txt = i18n( "<qt>Unable to open file <b>%1</b>.</qt>" );
+ KMessageBox::error( parentWidget(), txt.arg( fileName ) );
+ return false;
+ }
+
+ doExport( &file, list );
+ file.close();
+
+ return true;
+
+
+#endif //KAB_EMBEDDED
+
+}
+
+KABC::AddresseeList CSVXXPort::importContacts( const QString& ) const
+{
+ CSVImportDialog dlg( addressBook(), parentWidget() );
+ if ( dlg.exec() )
+ return dlg.contacts();
+ else
+ return KABC::AddresseeList();
+}
+
+void CSVXXPort::doExport( QFile *fp, const KABC::AddresseeList &list )
+{
+ QTextStream t( fp );
+
+ KABC::AddresseeList::ConstIterator iter;
+ KABC::Field::List fields = addressBook()->fields();
+ KABC::Field::List::Iterator fieldIter;
+ bool first = true;
+
+ // First output the column headings
+ for ( fieldIter = fields.begin(); fieldIter != fields.end(); ++fieldIter ) {
+ if ( !first )
+ t << ",";
+
+ t << "\"" << (*fieldIter)->label() << "\"";
+ first = false;
+ }
+ t << "\n";
+
+ // Then all the addressee objects
+ KABC::Addressee addr;
+ for ( iter = list.begin(); iter != list.end(); ++iter ) {
+ addr = *iter;
+ first = true;
+
+ for ( fieldIter = fields.begin(); fieldIter != fields.end(); ++fieldIter ) {
+ if ( !first )
+ t << ",";
+
+ t << "\"" << (*fieldIter)->value( addr ).replace( QRegExp("\n"), "\\n" ) << "\"";
+ first = false;
+ }
+
+ t << "\n";
+ }
+}
+
+#ifndef KAB_EMBEDDED
+#include "csv_xxport.moc"
+#endif //KAB_EMBEDDED
+
+
diff --git a/kaddressbook/xxport/csv_xxport.h b/kaddressbook/xxport/csv_xxport.h
new file mode 100644
index 0000000..fe6b3c6
--- a/dev/null
+++ b/kaddressbook/xxport/csv_xxport.h
@@ -0,0 +1,68 @@
+/*
+ This file is part of KAddressbook.
+ Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+/*
+Enhanced Version of the file for platform independent KDE tools.
+Copyright (c) 2004 Ulf Schenk
+
+$Id$
+*/
+
+#ifndef CSV_XXPORT_H
+#define CSV_XXPORT_H
+
+#include <xxportobject.h>
+
+class QFile;
+
+
+class CSVXXPort : public XXPortObject
+{
+ Q_OBJECT
+
+ public:
+ CSVXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name = 0 );
+
+ QString identifier() const { return "csv"; }
+
+ public slots:
+ bool exportContacts( const KABC::AddresseeList &list, const QString &data );
+ KABC::AddresseeList importContacts( const QString &data ) const;
+
+ private:
+ void doExport( QFile *fp, const KABC::AddresseeList &list );
+};
+
+#ifdef KAB_EMBEDDED
+class CSVXXPortFactory : public XXPortFactory
+{
+ public:
+ XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name )
+ {
+ return new CSVXXPort( ab, parent, name );
+ }
+};
+#endif //KAB_EMBEDDED
+
+
+#endif
diff --git a/kaddressbook/xxport/csvimportdialog.cpp b/kaddressbook/xxport/csvimportdialog.cpp
new file mode 100644
index 0000000..1093f9c
--- a/dev/null
+++ b/kaddressbook/xxport/csvimportdialog.cpp
@@ -0,0 +1,922 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (C) 2003 Tobias Koenig <tokoe@kde.org>
+ based on the code of KSpread's CSV Import Dialog
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+/*
+Enhanced Version of the file for platform independent KDE tools.
+Copyright (c) 2004 Ulf Schenk
+
+$Id$
+*/
+
+
+#include <qbuttongroup.h>
+#include <qcheckbox.h>
+#include <qcombobox.h>
+#include <qinputdialog.h>
+#include <qlabel.h>
+#include <qlineedit.h>
+#include <qpushbutton.h>
+#include <qradiobutton.h>
+#include <qtable.h>
+#include <qlayout.h>
+#include <qtextstream.h>
+#include <qfile.h>
+
+#include <kapplication.h>
+#include <kdebug.h>
+#include <kdialogbase.h>
+#include <kfiledialog.h>
+#include <klineedit.h>
+#include <klocale.h>
+#include <kglobal.h>
+#include <kmessagebox.h>
+#include <kstandarddirs.h>
+#include <kurlrequester.h>
+
+#ifdef DESKTOP_VERSION
+#include "qtable.h"
+#else
+#include "qcombotableitem.h"
+#endif
+#include "csvimportdialog.h"
+
+CSVImportDialog::CSVImportDialog( KABC::AddressBook *ab, QWidget *parent,
+ const char * name )
+ : KDialogBase( Plain, i18n ( "CSV Import Dialog" ), Ok | Cancel | User1 |
+ User2, Ok, parent, name, true, true ),
+ mAdjustRows( false ),
+ mStartLine( 0 ),
+ mTextQuote( '"' ),
+ mDelimiter( "," ),
+ mAddressBook( ab )
+{
+ initGUI();
+
+ mTypeMap.insert( i18n( "Undefined" ), Undefined );
+ mTypeMap.insert( KABC::Addressee::formattedNameLabel(), FormattedName );
+ mTypeMap.insert( KABC::Addressee::familyNameLabel(), FamilyName );
+ mTypeMap.insert( KABC::Addressee::givenNameLabel(), GivenName );
+ mTypeMap.insert( KABC::Addressee::additionalNameLabel(), AdditionalName );
+ mTypeMap.insert( KABC::Addressee::prefixLabel(), Prefix );
+ mTypeMap.insert( KABC::Addressee::suffixLabel(), Suffix );
+ mTypeMap.insert( KABC::Addressee::nickNameLabel(), NickName );
+ mTypeMap.insert( KABC::Addressee::birthdayLabel(), Birthday );
+
+ mTypeMap.insert( KABC::Addressee::homeAddressStreetLabel(), HomeAddressStreet );
+ mTypeMap.insert( KABC::Addressee::homeAddressLocalityLabel(),
+ HomeAddressLocality );
+ mTypeMap.insert( KABC::Addressee::homeAddressRegionLabel(), HomeAddressRegion );
+ mTypeMap.insert( KABC::Addressee::homeAddressPostalCodeLabel(),
+ HomeAddressPostalCode );
+ mTypeMap.insert( KABC::Addressee::homeAddressCountryLabel(),
+ HomeAddressCountry );
+ mTypeMap.insert( KABC::Addressee::homeAddressLabelLabel(), HomeAddressLabel );
+
+ mTypeMap.insert( KABC::Addressee::businessAddressStreetLabel(),
+ BusinessAddressStreet );
+ mTypeMap.insert( KABC::Addressee::businessAddressLocalityLabel(),
+ BusinessAddressLocality );
+ mTypeMap.insert( KABC::Addressee::businessAddressRegionLabel(),
+ BusinessAddressRegion );
+ mTypeMap.insert( KABC::Addressee::businessAddressPostalCodeLabel(),
+ BusinessAddressPostalCode );
+ mTypeMap.insert( KABC::Addressee::businessAddressCountryLabel(),
+ BusinessAddressCountry );
+ mTypeMap.insert( KABC::Addressee::businessAddressLabelLabel(),
+ BusinessAddressLabel );
+
+ mTypeMap.insert( KABC::Addressee::homePhoneLabel(), HomePhone );
+ mTypeMap.insert( KABC::Addressee::businessPhoneLabel(), BusinessPhone );
+ mTypeMap.insert( KABC::Addressee::mobilePhoneLabel(), MobilePhone );
+ mTypeMap.insert( KABC::Addressee::homeFaxLabel(), HomeFax );
+ mTypeMap.insert( KABC::Addressee::businessFaxLabel(), BusinessFax );
+ mTypeMap.insert( KABC::Addressee::carPhoneLabel(), CarPhone );
+ mTypeMap.insert( KABC::Addressee::isdnLabel(), Isdn );
+ mTypeMap.insert( KABC::Addressee::pagerLabel(), Pager );
+ mTypeMap.insert( KABC::Addressee::emailLabel(), Email );
+ mTypeMap.insert( KABC::Addressee::mailerLabel(), Mailer );
+ mTypeMap.insert( KABC::Addressee::titleLabel(), Title );
+ mTypeMap.insert( KABC::Addressee::roleLabel(), Role );
+ mTypeMap.insert( KABC::Addressee::organizationLabel(), Organization );
+ mTypeMap.insert( KABC::Addressee::noteLabel(), Note );
+ mTypeMap.insert( KABC::Addressee::urlLabel(), URL );
+
+ mCustomCounter = mTypeMap.count();
+ int count = mCustomCounter;
+
+ KABC::Field::List fields = mAddressBook->fields( KABC::Field::CustomCategory );
+ KABC::Field::List::Iterator it;
+ for ( it = fields.begin(); it != fields.end(); ++it, ++count )
+ mTypeMap.insert( (*it)->label(), count );
+
+ connect( mDelimiterBox, SIGNAL( clicked( int ) ),
+ this, SLOT( delimiterClicked( int ) ) );
+ connect( mDelimiterEdit, SIGNAL( returnPressed() ),
+ this, SLOT( returnPressed() ) );
+ connect( mDelimiterEdit, SIGNAL( textChanged ( const QString& ) ),
+ this, SLOT( textChanged ( const QString& ) ) );
+ connect( mComboLine, SIGNAL( activated( const QString& ) ),
+ this, SLOT( lineSelected( const QString& ) ) );
+ connect( mComboQuote, SIGNAL( activated( const QString& ) ),
+ this, SLOT( textquoteSelected( const QString& ) ) );
+ connect( mIgnoreDuplicates, SIGNAL( stateChanged( int ) ),
+ this, SLOT( ignoreDuplicatesChanged( int ) ) );
+
+ connect( mUrlRequester, SIGNAL( returnPressed( const QString& ) ),
+ this, SLOT( setFile( const QString& ) ) );
+ connect( mUrlRequester, SIGNAL( urlSelected( const QString& ) ),
+ this, SLOT( setFile( const QString& ) ) );
+ connect( mUrlRequester->lineEdit(), SIGNAL( textChanged ( const QString& ) ),
+ this, SLOT( urlChanged( const QString& ) ) );
+
+ connect( this, SIGNAL( user1Clicked() ),
+ this, SLOT( applyTemplate() ) );
+
+ connect( this, SIGNAL( user2Clicked() ),
+ this, SLOT( saveTemplate() ) );
+
+ // if ( QApplication::desktop()->width() < 321 )
+ QIconSet icon = SmallIcon("filesave");
+
+ findButton( User2 )->setIconSet (icon ) ;
+ icon = SmallIcon("fileopen");
+ findButton( User1 )->setIconSet (icon ) ;
+ int wid = findButton( User2 )->sizeHint().height();
+ findButton( User2 )->setMaximumWidth( wid+4 );
+ findButton( User1 )->setMaximumWidth( wid+4 );
+}
+
+CSVImportDialog::~CSVImportDialog()
+{
+}
+
+KABC::AddresseeList CSVImportDialog::contacts() const
+{
+ KABC::AddresseeList contacts;
+
+ for ( int row = 1; row < mTable->numRows(); ++row ) {
+ KABC::Addressee a;
+ bool emptyRow = true;
+ KABC::Address addrHome( KABC::Address::Home );
+ KABC::Address addrWork( KABC::Address::Work );
+ for ( int col = 0; col < mTable->numCols(); ++col ) {
+
+ QComboTableItem *item = static_cast<QComboTableItem*>( mTable->item( 0, col ) );
+
+ if ( !item ) {
+ qDebug( "ERROR: item cast failed" );
+ continue;
+ }
+
+ QString value = mTable->text( row, col );
+ if ( !value.isEmpty() )
+ emptyRow = false;
+
+ switch ( posToType( item->currentItem() ) )
+ {
+ case Undefined:
+ continue;
+ break;
+ case FormattedName:
+ a.setFormattedName( value );
+ break;
+ case GivenName:
+ a.setGivenName( value );
+ break;
+ case FamilyName:
+ a.setFamilyName( value );
+ break;
+ case AdditionalName:
+ a.setAdditionalName( value );
+ break;
+ case Prefix:
+ a.setPrefix( value );
+ break;
+ case Suffix:
+ a.setSuffix( value );
+ break;
+ case NickName:
+ a.setNickName( value );
+ break;
+ case Birthday:
+//US
+//the generated code had the following format: a.setBirthday( QDate::fromString( value, Qt::ISODate ) );
+// But Qt::IsoDate and QDate::fromString was not specified. Do I have the wrong QT version ?
+ {
+ QDate dt = KGlobal::locale()->readDate( value, "%Y-%m-%d"); // = Qt::ISODate
+ a.setBirthday(dt);
+ }
+ break;
+ case Email:
+ if ( !value.isEmpty() )
+ a.insertEmail( value, true );
+ break;
+ case Role:
+ a.setRole( value );
+ break;
+ case Title:
+ a.setTitle( value );
+ break;
+ case Mailer:
+ a.setMailer( value );
+ break;
+ case URL:
+ a.setUrl( value );
+ break;
+ case Organization:
+ a.setOrganization( value );
+ break;
+ case Note:
+ a.setNote( value );
+ break;
+
+ case HomePhone:
+ if ( !value.isEmpty() ) {
+ KABC::PhoneNumber number( value, KABC::PhoneNumber::Home );
+ a.insertPhoneNumber( number );
+ }
+ break;
+ case BusinessPhone:
+ if ( !value.isEmpty() ) {
+ KABC::PhoneNumber number( value, KABC::PhoneNumber::Work );
+ a.insertPhoneNumber( number );
+ }
+ break;
+ case MobilePhone:
+ if ( !value.isEmpty() ) {
+ KABC::PhoneNumber number( value, KABC::PhoneNumber::Cell );
+ a.insertPhoneNumber( number );
+ }
+ break;
+ case HomeFax:
+ if ( !value.isEmpty() ) {
+ KABC::PhoneNumber number( value, KABC::PhoneNumber::Home |
+ KABC::PhoneNumber::Fax );
+ a.insertPhoneNumber( number );
+ }
+ break;
+ case BusinessFax:
+ if ( !value.isEmpty() ) {
+ KABC::PhoneNumber number( value, KABC::PhoneNumber::Work |
+ KABC::PhoneNumber::Fax );
+ a.insertPhoneNumber( number );
+ }
+ break;
+ case CarPhone:
+ if ( !value.isEmpty() ) {
+ KABC::PhoneNumber number( value, KABC::PhoneNumber::Car );
+ a.insertPhoneNumber( number );
+ }
+ break;
+ case Isdn:
+ if ( !value.isEmpty() ) {
+ KABC::PhoneNumber number( value, KABC::PhoneNumber::Isdn );
+ a.insertPhoneNumber( number );
+ }
+ break;
+ case Pager:
+ if ( !value.isEmpty() ) {
+ KABC::PhoneNumber number( value, KABC::PhoneNumber::Pager );
+ a.insertPhoneNumber( number );
+ }
+ break;
+
+ case HomeAddressStreet:
+ addrHome.setStreet( value );
+ break;
+ case HomeAddressLocality:
+ addrHome.setLocality( value );
+ break;
+ case HomeAddressRegion:
+ addrHome.setRegion( value );
+ break;
+ case HomeAddressPostalCode:
+ addrHome.setPostalCode( value );
+ break;
+ case HomeAddressCountry:
+ addrHome.setCountry( value );
+ break;
+ case HomeAddressLabel:
+ addrHome.setLabel( value );
+ break;
+
+ case BusinessAddressStreet:
+ addrWork.setStreet( value );
+ break;
+ case BusinessAddressLocality:
+ addrWork.setLocality( value );
+ break;
+ case BusinessAddressRegion:
+ addrWork.setRegion( value );
+ break;
+ case BusinessAddressPostalCode:
+ addrWork.setPostalCode( value );
+ break;
+ case BusinessAddressCountry:
+ addrWork.setCountry( value );
+ break;
+ case BusinessAddressLabel:
+ addrWork.setLabel( value );
+ break;
+ default:
+ KABC::Field::List fields = mAddressBook->fields( KABC::Field::CustomCategory );
+ KABC::Field::List::Iterator it;
+
+ int counter = 0;
+ for ( it = fields.begin(); it != fields.end(); ++it ) {
+ if ( counter == (int)( posToType( item->currentItem() ) - mCustomCounter ) )
+ {
+ (*it)->setValue( a, value );
+ continue;
+ }
+ ++counter;
+ }
+ break;
+ }
+ }
+
+ if ( !addrHome.isEmpty() )
+ a.insertAddress( addrHome );
+ if ( !addrWork.isEmpty() )
+ a.insertAddress( addrWork );
+
+ if ( !emptyRow && !a.isEmpty() )
+ contacts.append( a );
+ }
+
+ return contacts;
+}
+
+void CSVImportDialog::initGUI()
+{
+ QWidget* page = plainPage();
+
+ QGridLayout *layout = new QGridLayout( page, 1, 1, marginHintSmall(),
+ spacingHintSmall() );
+ QHBoxLayout *hbox = new QHBoxLayout();
+ hbox->setSpacing( spacingHint() );
+
+ QLabel *label = new QLabel( i18n( "File to import:" ), page );
+ hbox->addWidget( label );
+
+ mUrlRequester = new KURLRequester( page );
+ mUrlRequester->setFilter( "*.csv" );
+ hbox->addWidget( mUrlRequester );
+
+ layout->addMultiCellLayout( hbox, 0, 0, 0, 1 );
+
+ // Delimiter: comma, semicolon, tab, space, other
+ mDelimiterBox = new QButtonGroup( i18n( "Delimiter" ), page );
+ mDelimiterBox->setColumnLayout( 0, Qt::Vertical );
+ mDelimiterBox->layout()->setSpacing( spacingHint() );
+ mDelimiterBox->layout()->setMargin( marginHint() );
+ QGridLayout *delimiterLayout = new QGridLayout( mDelimiterBox->layout() );
+ delimiterLayout->setAlignment( Qt::AlignTop );
+ layout->addMultiCellWidget( mDelimiterBox, 1, 1, 0, 1 );
+
+ mRadioComma = new QRadioButton( i18n( "Comma" ), mDelimiterBox );
+ mRadioComma->setChecked( true );
+ delimiterLayout->addWidget( mRadioComma, 0, 0 );
+
+ mRadioSemicolon = new QRadioButton( i18n( "Semicolon" ), mDelimiterBox );
+ delimiterLayout->addWidget( mRadioSemicolon, 0, 1 );
+
+ mRadioTab = new QRadioButton( i18n( "Tabulator" ), mDelimiterBox );
+ delimiterLayout->addWidget( mRadioTab, 1, 0 );
+
+ mRadioSpace = new QRadioButton( i18n( "Space" ), mDelimiterBox );
+ delimiterLayout->addWidget( mRadioSpace, 1, 1 );
+
+ mRadioOther = new QRadioButton( i18n( "Other" ), mDelimiterBox );
+ delimiterLayout->addWidget( mRadioOther, 0, 2 );
+
+ mDelimiterEdit = new QLineEdit( mDelimiterBox );
+ delimiterLayout->addWidget( mDelimiterEdit, 1, 2 );
+
+ mComboLine = new QComboBox( false, page );
+ mComboLine->insertItem( i18n( "1" ) );
+ layout->addWidget( mComboLine, 3, 1 );
+
+ mComboQuote = new QComboBox( false, page );
+ mComboQuote->insertItem( i18n( "\"" ), 0 );
+ mComboQuote->insertItem( i18n( "'" ), 1 );
+ mComboQuote->insertItem( i18n( "None" ), 2 );
+ layout->addWidget( mComboQuote, 3, 0 );
+
+ label = new QLabel( i18n( "Start at line:" ), page );
+ layout->addWidget( label, 2, 1 );
+
+ label = new QLabel( i18n( "Textquote:" ), page );
+ layout->addWidget( label, 2, 0 );
+
+ mIgnoreDuplicates = new QCheckBox( page );
+ mIgnoreDuplicates->setText( i18n( "Ignore duplicate delimiters" ) );
+ layout->addMultiCellWidget( mIgnoreDuplicates, 4, 4, 0, 1 );
+
+ mTable = new QTable( 0, 0, page );
+ mTable->setSelectionMode( QTable::NoSelection );
+ //mTable->horizontalHeader()->hide();
+ layout->addMultiCellWidget( mTable, 5, 5, 0, 1 );
+/*US
+ setButtonText( User1, i18n( "Apply Template" ) );
+ setButtonText( User2, i18n( "Save Template" ) );
+*/
+
+ enableButtonOK( false );
+
+ findButton( User1 )->setEnabled( false );
+ findButton( User2 )->setEnabled( false );
+
+#ifdef DESKTOP_VERSION
+ resize( 500, 300 );
+#else
+ showMaximized();
+#endif
+}
+
+void CSVImportDialog::fillTable()
+{
+ int row, column;
+ bool lastCharDelimiter = false;
+ bool ignoreDups = mIgnoreDuplicates->isChecked();
+ enum { S_START, S_QUOTED_FIELD, S_MAYBE_END_OF_QUOTED_FIELD, S_END_OF_QUOTED_FIELD,
+ S_MAYBE_NORMAL_FIELD, S_NORMAL_FIELD } state = S_START;
+
+ QChar x;
+ QString field = "";
+
+ // store previous assignment
+ QValueList<int> mTypeOld = mTypeStore;
+
+ mTypeStore.clear();
+ for ( column = 0; column < mTable->numCols(); ++column ) {
+ QComboTableItem *item = static_cast<QComboTableItem*>( mTable->item( 0, column ) );
+
+ if ( !item || mClearTypeStore )
+ mTypeStore.append( typeToPos( Undefined ) );
+ else if ( item )
+ mTypeStore.append( item->currentItem() );
+ }
+
+ clearTable();
+
+ row = column = 1;
+ mData = QString( mFileArray );
+
+ QTextStream inputStream( mData, IO_ReadOnly );
+ inputStream.setEncoding( QTextStream::Locale );
+
+ int maxColumn = 0;
+ while ( !inputStream.atEnd() ) {
+ inputStream >> x; // read one char
+
+ if ( x == '\r' ) inputStream >> x; // eat '\r', to handle DOS/LOSEDOWS files correctly
+
+ switch ( state ) {
+ case S_START :
+ if ( x == mTextQuote ) {
+ state = S_QUOTED_FIELD;
+ } else if ( x == mDelimiter ) {
+ if ( ( ignoreDups == false ) || ( lastCharDelimiter == false ) )
+ ++column;
+ lastCharDelimiter = true;
+ } else if ( x == '\n' ) {
+ ++row;
+ column = 1;
+ } else {
+ field += x;
+ state = S_MAYBE_NORMAL_FIELD;
+ }
+ break;
+ case S_QUOTED_FIELD :
+ if ( x == mTextQuote ) {
+ state = S_MAYBE_END_OF_QUOTED_FIELD;
+ } else if ( x == '\n' ) {
+ setText( row - mStartLine + 1, column, field );
+ field = "";
+ if ( x == '\n' ) {
+ ++row;
+ column = 1;
+ } else {
+ if ( ( ignoreDups == false ) || ( lastCharDelimiter == false ) )
+ ++column;
+ lastCharDelimiter = true;
+ }
+ state = S_START;
+ } else {
+ field += x;
+ }
+ break;
+ case S_MAYBE_END_OF_QUOTED_FIELD :
+ if ( x == mTextQuote ) {
+ field += x;
+ state = S_QUOTED_FIELD;
+ } else if ( x == mDelimiter || x == '\n' ) {
+ setText( row - mStartLine + 1, column, field );
+ field = "";
+ if ( x == '\n' ) {
+ ++row;
+ column = 1;
+ } else {
+ if ( ( ignoreDups == false ) || ( lastCharDelimiter == false ) )
+ ++column;
+ lastCharDelimiter = true;
+ }
+ state = S_START;
+ } else {
+ state = S_END_OF_QUOTED_FIELD;
+ }
+ break;
+ case S_END_OF_QUOTED_FIELD :
+ if ( x == mDelimiter || x == '\n' ) {
+ setText( row - mStartLine + 1, column, field );
+ field = "";
+ if ( x == '\n' ) {
+ ++row;
+ column = 1;
+ } else {
+ if ( ( ignoreDups == false ) || ( lastCharDelimiter == false ) )
+ ++column;
+ lastCharDelimiter = true;
+ }
+ state = S_START;
+ } else {
+ state = S_END_OF_QUOTED_FIELD;
+ }
+ break;
+ case S_MAYBE_NORMAL_FIELD :
+ if ( x == mTextQuote ) {
+ field = "";
+ state = S_QUOTED_FIELD;
+ break;
+ }
+ case S_NORMAL_FIELD :
+ if ( x == mDelimiter || x == '\n' ) {
+ setText( row - mStartLine + 1, column, field );
+ field = "";
+ if ( x == '\n' ) {
+ ++row;
+ column = 1;
+ } else {
+ if ( ( ignoreDups == false ) || ( lastCharDelimiter == false ) )
+ ++column;
+ lastCharDelimiter = true;
+ }
+ state = S_START;
+ } else {
+ field += x;
+ }
+ }
+ if ( x != mDelimiter )
+ lastCharDelimiter = false;
+
+ if ( column > maxColumn )
+ maxColumn = column;
+ }
+
+ // file with only one line without '\n'
+ if ( field.length() > 0 ) {
+ setText( row - mStartLine + 1, column, field );
+ ++row;
+ field = "";
+ }
+
+ adjustRows( row - mStartLine );
+ mTable->setNumCols( maxColumn );
+
+//US begin
+ QStringList keys;
+ QMap<QString, uint>::ConstIterator it;
+ for ( it = mTypeMap.begin(); it != mTypeMap.end(); ++it)
+ keys << it.key();
+//US end
+
+ for ( column = 0; column < mTable->numCols(); ++column ) {
+
+//US QComboTableItem *item = new QComboTableItem( mTable, mTypeMap.keys() );
+ QComboTableItem *item = new QComboTableItem( mTable, keys );
+ mTable->setItem( 0, column, item );
+ if ( column < mTypeStore.count() )
+ item->setCurrentItem( mTypeStore[ column ] );
+ else
+ item->setCurrentItem( typeToPos( Undefined ) );
+
+ mTable->adjustColumn( column );
+ }
+}
+
+void CSVImportDialog::clearTable()
+{
+ for ( int row = 0; row < mTable->numRows(); ++row )
+ for ( int column = 0; column < mTable->numCols(); ++column )
+ mTable->clearCell( row, column );
+}
+
+void CSVImportDialog::fillComboBox()
+{
+ mComboLine->clear();
+ for ( int row = 1; row < mTable->numRows() + 1; ++row )
+ mComboLine->insertItem( QString::number( row ), row - 1 );
+}
+
+void CSVImportDialog::setText( int row, int col, const QString& text )
+{
+ if ( row < 1 ) // skipped by the user
+ return;
+
+ if ( mTable->numRows() < row ) {
+ mTable->setNumRows( row + 5000 ); // We add 5000 at a time to limit recalculations
+ mAdjustRows = true;
+ }
+
+ if ( mTable->numCols() < col )
+ mTable->setNumCols( col + 50 ); // We add 50 at a time to limit recalculation
+
+ mTable->setText( row - 1, col - 1, text );
+}
+
+/*
+ * Called after the first fillTable() when number of rows are unknown.
+ */
+void CSVImportDialog::adjustRows( int rows )
+{
+ if ( mAdjustRows ) {
+ mTable->setNumRows( rows );
+ mAdjustRows = false;
+ }
+}
+
+void CSVImportDialog::returnPressed()
+{
+ if ( mDelimiterBox->id( mDelimiterBox->selected() ) != 4 )
+ return;
+
+ mDelimiter = mDelimiterEdit->text();
+ fillTable();
+}
+
+void CSVImportDialog::textChanged ( const QString& )
+{
+ mRadioOther->setChecked ( true );
+ delimiterClicked( 4 ); // other
+}
+
+void CSVImportDialog::delimiterClicked( int id )
+{
+ switch ( id ) {
+ case 0: // comma
+ mDelimiter = ",";
+ break;
+ case 4: // other
+ mDelimiter = mDelimiterEdit->text();
+ break;
+ case 2: // tab
+ mDelimiter = "\t";
+ break;
+ case 3: // space
+ mDelimiter = " ";
+ break;
+ case 1: // semicolon
+ mDelimiter = ";";
+ break;
+ }
+
+ fillTable();
+}
+
+void CSVImportDialog::textquoteSelected( const QString& mark )
+{
+ if ( mComboQuote->currentItem() == 2 )
+ mTextQuote = 0;
+ else
+ mTextQuote = mark[ 0 ];
+
+ fillTable();
+}
+
+void CSVImportDialog::lineSelected( const QString& line )
+{
+ mStartLine = line.toInt() - 1;
+ fillTable();
+}
+
+void CSVImportDialog::slotOk()
+{
+ bool assigned = false;
+
+ for ( int column = 0; column < mTable->numCols(); ++column ) {
+ QComboTableItem *item = static_cast<QComboTableItem*>( mTable->item( 0,
+ column ) );
+ if ( item && posToType( item->currentItem() ) != Undefined )
+ assigned = true;
+ }
+
+ if ( assigned )
+ KDialogBase::slotOk();
+ else
+ KMessageBox::sorry( this, i18n( "You have to assign at least one column." ) );
+}
+
+void CSVImportDialog::applyTemplate()
+{
+ QMap<uint,int> columnMap;
+ QMap<QString, QString> fileMap;
+ QStringList templates;
+
+ // load all template files
+/*US QStringList list = KGlobal::dirs()->findAllResources( "data" , QString( kapp->name() ) +
+ "/csv-templates/*.desktop", true, true );
+*/
+ QStringList list = KGlobal::dirs()->findAllResources( "data" , KGlobal::getAppName() +
+ "/csv-templates/*.desktop", true, true );
+
+ for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it )
+ {
+ qDebug("for ");
+//US KSimpleConfig config( *it, true );
+ KConfig config( *it );
+
+ if ( !config.hasGroup( "csv column map" ) )
+ continue;
+
+ config.setGroup( "Misc" );
+ templates.append( config.readEntry( "Name" ) );
+ fileMap.insert( config.readEntry( "Name" ), *it );
+ }
+ qDebug("weiter ");
+ // let the user chose, what to take
+ bool ok = false;
+ QString tmp;
+ tmp = QInputDialog::getItem( i18n( "Template Selection" ),
+ i18n( "Please select a template, that matches the CSV file." ),
+ templates, 0, false, &ok, this );
+
+ if ( !ok )
+ return;
+
+//US KSimpleConfig config( fileMap[ tmp ], true );
+ KConfig config( fileMap[ tmp ] );
+ config.setGroup( "General" );
+//US uint numColumns = config.readUnsignedNumEntry( "Columns" );
+ uint numColumns = (uint)config.readNumEntry( "Columns" );
+
+ mDelimiterEdit->setText( config.readEntry( "DelimiterOther" ) );
+ mDelimiterBox->setButton( config.readNumEntry( "DelimiterType" ) );
+ delimiterClicked( config.readNumEntry( "DelimiterType" ) );
+ int quoteType = config.readNumEntry( "QuoteType" );
+ mComboQuote->setCurrentItem( quoteType );
+ textquoteSelected( mComboQuote->currentText() );
+
+ // create the column map
+ config.setGroup( "csv column map" );
+ for ( uint i = 0; i < numColumns; ++i ) {
+ int col = config.readNumEntry( QString::number( i ) );
+ columnMap.insert( i, col );
+ }
+
+ // apply the column map
+ for ( uint column = 0; column < columnMap.count(); ++column ) {
+ int type = columnMap[ column ];
+ QComboTableItem *item = static_cast<QComboTableItem*>( mTable->item( 0,
+ column ) );
+ if ( item )
+ item->setCurrentItem( typeToPos( type ) );
+ }
+}
+
+void CSVImportDialog::saveTemplate()
+{
+/*US
+ QString fileName = KFileDialog::getSaveFileName(
+ locateLocal( "data", QString( kapp->name() ) + "/csv-templates/" ),
+ "*.desktop", this );
+*/
+ QString fileName = KFileDialog::getSaveFileName(
+ locateLocal( "data", KGlobal::getAppName() + "/csv-templates/" )+
+ "*.desktop",i18n("Save file name") , this );
+
+ if ( fileName.isEmpty() )
+ return;
+
+ if ( !fileName.contains( ".desktop" ) )
+ fileName += ".desktop";
+
+ QString name = QInputDialog::getText( i18n( "Template name" ), i18n( "Please enter a name for the template" ) );
+
+ if ( name.isEmpty() )
+ return;
+
+ KConfig config( fileName );
+ config.setGroup( "General" );
+ config.writeEntry( "Columns", mTable->numCols() );
+ config.writeEntry( "DelimiterType", mDelimiterBox->id( mDelimiterBox->selected() ) );
+ config.writeEntry( "DelimiterOther", mDelimiterEdit->text() );
+ config.writeEntry( "QuoteType", mComboQuote->currentItem() );
+
+ config.setGroup( "Misc" );
+ config.writeEntry( "Name", name );
+
+ config.setGroup( "csv column map" );
+
+ for ( uint column = 0; column < mTable->numCols(); ++column ) {
+ QComboTableItem *item = static_cast<QComboTableItem*>( mTable->item( 0,
+ column ) );
+ if ( item )
+ config.writeEntry( QString::number( column ), posToType(
+ item->currentItem() ) );
+ else
+ config.writeEntry( QString::number( column ), 0 );
+ }
+
+ config.sync();
+}
+
+QString CSVImportDialog::getText( int row, int col )
+{
+ return mTable->text( row, col );
+}
+
+uint CSVImportDialog::posToType( int pos ) const
+{
+ uint counter = 0;
+ QMap<QString, uint>::ConstIterator it;
+ for ( it = mTypeMap.begin(); it != mTypeMap.end(); ++it, ++counter )
+ if ( counter == (uint)pos )
+ return it.data();
+
+ return 0;
+}
+
+int CSVImportDialog::typeToPos( uint type ) const
+{
+ uint counter = 0;
+ QMap<QString, uint>::ConstIterator it;
+ for ( it = mTypeMap.begin(); it != mTypeMap.end(); ++it, ++counter )
+ if ( it.data() == type )
+ return counter;
+
+ return -1;
+}
+
+void CSVImportDialog::ignoreDuplicatesChanged( int )
+{
+ fillTable();
+}
+
+void CSVImportDialog::setFile( const QString &fileName )
+{
+ if ( fileName.isEmpty() )
+ return;
+
+ QFile file( fileName );
+ if ( !file.open( IO_ReadOnly ) ) {
+ KMessageBox::sorry( this, i18n( "Cannot open input file!" ) );
+ file.close();
+ return;
+ }
+
+ mFileArray = file.readAll();
+ file.close();
+
+ mClearTypeStore = true;
+ clearTable();
+ mTable->setNumCols( 0 );
+ mTable->setNumRows( 0 );
+ fillTable();
+ mClearTypeStore = false;
+
+ fillComboBox();
+}
+
+void CSVImportDialog::urlChanged( const QString &file )
+{
+ bool state = !file.isEmpty();
+
+ enableButtonOK( state );
+
+ findButton( User1 )->setEnabled( state );
+ findButton( User2 )->setEnabled( state );
+
+}
+
+#ifndef KAB_EMBEDDED
+#include <csvimportdialog.moc>
+#endif //KAB_EMBEDDED
diff --git a/kaddressbook/xxport/csvimportdialog.h b/kaddressbook/xxport/csvimportdialog.h
new file mode 100644
index 0000000..545b5f9
--- a/dev/null
+++ b/kaddressbook/xxport/csvimportdialog.h
@@ -0,0 +1,124 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (C) 2003 Tobias Koenig <tokoe@kde.org>
+ based on the code of KSpread's CSV Import Dialog
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+/*
+Enhanced Version of the file for platform independent KDE tools.
+Copyright (c) 2004 Ulf Schenk
+
+$Id$
+*/
+
+#ifndef CSV_IMPORT_DLG_H
+#define CSV_IMPORT_DLG_H
+
+#include <kabc/addressbook.h>
+#include <kabc/addresseelist.h>
+#include <kdialogbase.h>
+
+#include <qvaluelist.h>
+
+class KURLRequester;
+
+class QButtonGroup;
+class QComboBox;
+class QCheckBox;
+class QLineEdit;
+class QPushButton;
+class QRadioButton;
+class QTable;
+
+class CSVImportDialog : public KDialogBase
+{
+ Q_OBJECT
+
+ public:
+ CSVImportDialog( KABC::AddressBook *ab, QWidget *parent,
+ const char *name = 0 );
+ ~CSVImportDialog();
+
+ KABC::AddresseeList contacts() const;
+
+ protected slots:
+ virtual void slotOk();
+
+ private slots:
+ void returnPressed();
+ void delimiterClicked( int id );
+ void lineSelected( const QString& line );
+ void textquoteSelected( const QString& mark );
+ void textChanged ( const QString & );
+ void ignoreDuplicatesChanged( int );
+ void setFile( const QString& );
+ void urlChanged( const QString& );
+
+ void applyTemplate();
+ void saveTemplate();
+
+ private:
+ enum { Undefined, FormattedName, FamilyName, GivenName, AdditionalName,
+ Prefix, Suffix, NickName, Birthday,
+ HomeAddressStreet, HomeAddressLocality, HomeAddressRegion,
+ HomeAddressPostalCode, HomeAddressCountry, HomeAddressLabel,
+ BusinessAddressStreet, BusinessAddressLocality, BusinessAddressRegion,
+ BusinessAddressPostalCode, BusinessAddressCountry,
+ BusinessAddressLabel,
+ HomePhone, BusinessPhone, MobilePhone, HomeFax, BusinessFax, CarPhone,
+ Isdn, Pager, Email, Mailer, Title, Role, Organization, Note, URL
+ };
+
+ QTable* mTable;
+ QButtonGroup* mDelimiterBox;
+ QRadioButton* mRadioComma;
+ QRadioButton* mRadioSemicolon;
+ QRadioButton* mRadioTab;
+ QRadioButton* mRadioSpace;
+ QRadioButton* mRadioOther;
+ QLineEdit* mDelimiterEdit;
+ QComboBox* mComboLine;
+ QComboBox* mComboQuote;
+ QCheckBox* mIgnoreDuplicates;
+ KURLRequester* mUrlRequester;
+
+ void initGUI();
+ void fillTable();
+ void clearTable();
+ void fillComboBox();
+ void setText( int row, int col, const QString& text );
+ void adjustRows( int rows );
+ QString getText( int row, int col );
+ uint posToType( int pos ) const;
+ int typeToPos( uint type ) const;
+
+ bool mAdjustRows;
+ int mStartLine;
+ QChar mTextQuote;
+ QString mDelimiter;
+ QString mData;
+ QByteArray mFileArray;
+ QMap<QString, uint> mTypeMap;
+ KABC::AddressBook *mAddressBook;
+ int mCustomCounter;
+ bool mClearTypeStore;
+ QValueList<int> mTypeStore;
+
+};
+
+#endif
diff --git a/kaddressbook/xxport/kde2_xxport.cpp b/kaddressbook/xxport/kde2_xxport.cpp
new file mode 100644
index 0000000..d5fc075
--- a/dev/null
+++ b/kaddressbook/xxport/kde2_xxport.cpp
@@ -0,0 +1,116 @@
+/*
+ This file is part of KAddressbook.
+ Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+/*
+Enhanced Version of the file for platform independent KDE tools.
+Copyright (c) 2004 Ulf Schenk
+
+$Id$
+*/
+
+#include <qfile.h>
+
+#include <kdebug.h>
+#include <kfiledialog.h>
+#ifndef KAB_EMBEDDED
+#include <kio/netaccess.h>
+#endif //KAB_EMBEDDED
+#include <klocale.h>
+#include <kmessagebox.h>
+#include <kprocess.h>
+#include <kstandarddirs.h>
+#include <ktempfile.h>
+#include <kurl.h>
+
+#include "xxportmanager.h"
+
+#include "kde2_xxport.h"
+
+#ifndef KAB_EMBEDDED
+
+class KDE2XXPortFactory : public XXPortFactory
+{
+ public:
+ XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name )
+ {
+ return new KDE2XXPort( ab, parent, name );
+ }
+};
+
+
+extern "C"
+{
+ void *init_libkaddrbk_kde2_xxport()
+ {
+ return ( new KDE2XXPortFactory() );
+ }
+}
+#endif //KAB_EMBEDDED
+
+
+KDE2XXPort::KDE2XXPort( KABC::AddressBook *ab, QWidget *parent, const char *name )
+ : XXPortObject( ab, parent, name )
+{
+ createImportAction( i18n( "Import KDE 2 Addressbook..." ) );
+}
+
+KABC::AddresseeList KDE2XXPort::importContacts( const QString& ) const
+{
+ QString fileName = locateLocal( "data", "kabc/std.vcf" );
+ if ( !QFile::exists( fileName ) ) {
+ KMessageBox::sorry( parentWidget(), i18n( "<qt>Couldn't find a KDE 2 address book <b>%1</b>.</qt>" ).arg( fileName ) );
+ return KABC::AddresseeList();
+ }
+
+#ifndef KAB_EMBEDDED
+ int result = KMessageBox::questionYesNoCancel( parentWidget(),
+ i18n( "Override previously imported entries?" ),
+ i18n( "Import KDE 2 Addressbook" ) );
+#else //KAB_EMBEDDED
+ int result = KMessageBox::warningYesNoCancel( parentWidget(),
+ i18n( "Override previously imported entries?" ),
+ i18n( "Import KDE 2 Addressbook" ) );
+#endif //KAB_EMBEDDED
+
+ if ( !result ) return KABC::AddresseeList();
+
+ KProcess proc;
+
+ if ( result == KMessageBox::Yes ) {
+ proc << "kab2kabc";
+ proc << "--override";
+ } else if ( result == KMessageBox::No )
+ proc << "kab2kabc";
+ else
+ kdDebug(5720) << "KAddressBook::importKDE2(): Unknow return value." << endl;
+
+ proc.start( KProcess::Block );
+
+ addressBook()->load();
+
+ return KABC::AddresseeList();
+}
+
+#ifndef KAB_EMBEDDED
+#include "kde2_xxport.moc"
+#endif //KAB_EMBEDDED
diff --git a/kaddressbook/xxport/kde2_xxport.h b/kaddressbook/xxport/kde2_xxport.h
new file mode 100644
index 0000000..4fb1d0b
--- a/dev/null
+++ b/kaddressbook/xxport/kde2_xxport.h
@@ -0,0 +1,62 @@
+/*
+ This file is part of KAddressbook.
+ Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+/*
+Enhanced Version of the file for platform independent KDE tools.
+Copyright (c) 2004 Ulf Schenk
+
+$Id$
+*/
+
+#ifndef KDE2_XXPORT_H
+#define KDE2_XXPORT_H
+
+#include <xxportobject.h>
+
+class KDE2XXPort : public XXPortObject
+{
+ Q_OBJECT
+
+ public:
+ KDE2XXPort( KABC::AddressBook *ab, QWidget *parent, const char *name = 0 );
+
+ QString identifier() const { return "kde2"; }
+
+ public slots:
+ KABC::AddresseeList importContacts( const QString &data ) const;
+};
+
+
+#ifdef KAB_EMBEDDED
+class KDE2XXPortFactory : public XXPortFactory
+{
+ public:
+ XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name )
+ {
+ return new KDE2XXPort( ab, parent, name );
+ }
+};
+#endif //KAB_EMBEDDED
+
+
+#endif
diff --git a/kaddressbook/xxport/vcard_xxport.cpp b/kaddressbook/xxport/vcard_xxport.cpp
new file mode 100644
index 0000000..dd49a9c
--- a/dev/null
+++ b/kaddressbook/xxport/vcard_xxport.cpp
@@ -0,0 +1,238 @@
+/*
+ This file is part of KAddressbook.
+ Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+/*
+Enhanced Version of the file for platform independent KDE tools.
+Copyright (c) 2004 Ulf Schenk
+
+$Id$
+*/
+
+#include <qfile.h>
+#include <qtextstream.h>
+
+#include <kabc/vcardconverter.h>
+#include <kfiledialog.h>
+#ifndef KAB_EMBEDDED
+#include <kio/netaccess.h>
+#endif //KAB_EMBEDDED
+
+#include <klocale.h>
+#include <kmessagebox.h>
+#include <ktempfile.h>
+#include <kurl.h>
+
+#include "xxportmanager.h"
+
+#include "vcard_xxport.h"
+
+#ifndef KAB_EMBEDDED
+
+class VCardXXPortFactory : public XXPortFactory
+{
+ public:
+ XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name )
+ {
+ return new VCardXXPort( ab, parent, name );
+ }
+};
+
+
+extern "C"
+{
+ void *init_libkaddrbk_vcard_xxport()
+ {
+ return ( new VCardXXPortFactory() );
+ }
+}
+#endif //KAB_EMBEDDED
+
+
+VCardXXPort::VCardXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name )
+ : XXPortObject( ab, parent, name )
+{
+ createImportAction( i18n( "Import vCard..." ) );
+ createExportAction( i18n( "Export vCard 2.1..." ), "v21" );
+ createExportAction( i18n( "Export vCard 3.0..." ), "v30" );
+}
+
+bool VCardXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data )
+{
+ QString name;
+
+ if ( list.count() == 1 )
+ name = list[ 0 ].givenName() + "_" + list[ 0 ].familyName() + ".vcf";
+ else
+ name = "addressbook.vcf";
+
+#ifndef KAB_EMBEDDED
+ QString fileName = KFileDialog::getSaveFileName( name );
+#else //KAB_EMBEDDED
+ QString fileName = KFileDialog::getSaveFileName( name, i18n("Save file"), parentWidget() );
+#endif //KAB_EMBEDDED
+
+ if ( fileName.isEmpty() )
+ return true;
+
+ QFile outFile( fileName );
+ if ( !outFile.open( IO_WriteOnly ) ) {
+ QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" );
+ KMessageBox::error( parentWidget(), text.arg( fileName ) );
+ return false;
+ }
+
+ QTextStream t( &outFile );
+ t.setEncoding( QTextStream::UnicodeUTF8 );
+
+ KABC::Addressee::List::ConstIterator it;
+ for ( it = list.begin(); it != list.end(); ++it ) {
+ KABC::VCardConverter converter;
+ QString vcard;
+
+ KABC::VCardConverter::Version version;
+ if ( data == "v21" )
+ version = KABC::VCardConverter::v2_1;
+ else
+ version = KABC::VCardConverter::v3_0;
+
+ converter.addresseeToVCard( *it, vcard, version );
+ t << vcard << "\r\n\r\n";
+ }
+
+ outFile.close();
+
+ return true;
+}
+
+KABC::AddresseeList VCardXXPort::importContacts( const QString& ) const
+{
+ QString fileName;
+ KABC::AddresseeList addrList;
+ KURL url;
+
+#ifndef KAB_EMBEDDED
+ if ( !XXPortManager::importData.isEmpty() )
+ addrList = parseVCard( XXPortManager::importData );
+ else {
+ if ( XXPortManager::importURL.isEmpty() )
+ {
+ url = KFileDialog::getLoadFileName( QString::null, i18n("Select vCard to Import"), parentWidget() );
+ }
+ else
+ url = XXPortManager::importURL;
+
+ if ( url.isEmpty() )
+ return addrList;
+
+ QString caption( i18n( "vCard Import Failed" ) );
+ if ( KIO::NetAccess::download( url, fileName ) ) {
+ QFile file( fileName );
+
+ file.open( IO_ReadOnly );
+ QByteArray rawData = file.readAll();
+ file.close();
+
+ QString data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
+ addrList = parseVCard( data );
+
+ if ( !url.isLocalFile() )
+ KIO::NetAccess::removeTempFile( fileName );
+
+ } else {
+ QString text = i18n( "<qt>Unable to access <b>%1</b>.</qt>" );
+ KMessageBox::error( parentWidget(), text.arg( url.url() ), caption );
+ }
+
+ }
+
+
+#else //KAB_EMBEDDED
+
+
+ if ( !XXPortManager::importData.isEmpty() )
+ addrList = parseVCard( XXPortManager::importData );
+ else {
+ if ( XXPortManager::importURL.isEmpty() )
+ {
+ fileName = KFileDialog::getOpenFileName( QString::null, i18n("Select vCard to Import"), parentWidget() );
+ }
+ else
+ {
+//US url = XXPortManager::importURL;
+ qDebug("VCardXXPort::importContacts Urls at the moment not supported");
+ }
+
+ if ( url.isEmpty() )
+ return addrList;
+
+ QFile file( fileName );
+
+ file.open( IO_ReadOnly );
+ QByteArray rawData = file.readAll();
+ file.close();
+
+ QString data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
+ addrList = parseVCard( data );
+
+ }
+#endif //KAB_EMBEDDED
+
+ return addrList;
+}
+
+KABC::AddresseeList VCardXXPort::parseVCard( const QString &data ) const
+{
+ KABC::VCardConverter converter;
+ KABC::AddresseeList addrList;
+
+ uint numVCards = data.contains( "BEGIN:VCARD", false );
+ QStringList dataList = QStringList::split( "\r\n\r\n", data );
+
+ for ( uint i = 0; i < numVCards && i < dataList.count(); ++i ) {
+ KABC::Addressee addr;
+ bool ok = false;
+
+ if ( dataList[ i ].contains( "VERSION:3.0" ) )
+ ok = converter.vCardToAddressee( dataList[ i ], addr, KABC::VCardConverter::v3_0 );
+ else if ( dataList[ i ].contains( "VERSION:2.1" ) )
+ ok = converter.vCardToAddressee( dataList[ i ], addr, KABC::VCardConverter::v2_1 );
+ else {
+ KMessageBox::sorry( parentWidget(), i18n( "Not supported vCard version." ) );
+ continue;
+ }
+
+ if ( !addr.isEmpty() && ok )
+ addrList.append( addr );
+ else {
+ QString text = i18n( "The selected file does not include a valid vCard. "
+ "Please check the file and try again." );
+ KMessageBox::sorry( parentWidget(), text );
+ }
+ }
+
+ return addrList;
+}
+
+#ifndef KAB_EMBEDDED
+#include "vcard_xxport.moc"
+#endif //KAB_EMBEDDED
diff --git a/kaddressbook/xxport/vcard_xxport.h b/kaddressbook/xxport/vcard_xxport.h
new file mode 100644
index 0000000..b9708a9
--- a/dev/null
+++ b/kaddressbook/xxport/vcard_xxport.h
@@ -0,0 +1,64 @@
+/*
+ This file is part of KAddressbook.
+ Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+/*
+Enhanced Version of the file for platform independent KDE tools.
+Copyright (c) 2004 Ulf Schenk
+
+$Id$
+*/
+
+#ifndef VCARD_XXPORT_H
+#define VCARD_XXPORT_H
+
+#include <xxportobject.h>
+
+class VCardXXPort : public XXPortObject
+{
+ Q_OBJECT
+
+ public:
+ VCardXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name = 0 );
+
+ QString identifier() const { return "vcard"; }
+
+ public slots:
+ bool exportContacts( const KABC::AddresseeList &list, const QString &data );
+ KABC::AddresseeList importContacts( const QString &data ) const;
+
+ private:
+ KABC::AddresseeList parseVCard( const QString &data ) const;
+};
+
+#ifdef KAB_EMBEDDED
+class VCardXXPortFactory : public XXPortFactory
+{
+ public:
+ XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name )
+ {
+ return new VCardXXPort( ab, parent, name );
+ }
+};
+#endif //KAB_EMBEDDED
+
+#endif
diff --git a/kaddressbook/xxportmanager.cpp b/kaddressbook/xxportmanager.cpp
new file mode 100644
index 0000000..6cfa9cb
--- a/dev/null
+++ b/kaddressbook/xxportmanager.cpp
@@ -0,0 +1,269 @@
+/*
+ This file is part of KAddressbook.
+ Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+/*
+Enhanced Version of the file for platform independent KDE tools.
+Copyright (c) 2004 Ulf Schenk
+
+$Id$
+*/
+
+#include <qlayout.h>
+
+#include <kabc/addressbook.h>
+#include <kabc/resource.h>
+#include <kdebug.h>
+#include <kdialogbase.h>
+#include <klocale.h>
+#include <kmessagebox.h>
+
+#ifndef KAB_EMBEDDED
+#include <ktrader.h>
+#else //KAB_EMBEDDED
+#include "xxport/csv_xxport.h"
+#include "xxport/kde2_xxport.h"
+#include "xxport/vcard_xxport.h"
+#endif //KAB_EMBEDDED
+
+#include <libkdepim/addresseeview.h>
+
+#include "kabcore.h"
+#include "undocmds.h"
+#include "xxportselectdialog.h"
+
+#include "xxportmanager.h"
+
+KURL XXPortManager::importURL = KURL();
+QString XXPortManager::importData = QString::null;
+
+class PreviewDialog : public KDialogBase
+{
+ public:
+ PreviewDialog( const KABC::Addressee &addr,
+ QWidget *parent, const char *name = 0 );
+};
+
+XXPortManager::XXPortManager( KABCore *core, QObject *parent, const char *name )
+ : QObject( parent, name ), mCore( core ), mShowPreview( false )
+{
+ loadPlugins();
+}
+
+XXPortManager::~XXPortManager()
+{
+}
+
+void XXPortManager::restoreSettings()
+{
+}
+
+void XXPortManager::saveSettings()
+{
+}
+
+void XXPortManager::importVCard( const KURL &url )
+{
+ importVCard( url, false );
+}
+
+void XXPortManager::importVCard( const KURL &url, bool showPreview )
+{
+ importURL = url;
+ mShowPreview = showPreview;
+ slotImport( "vcard", "<empty>" );
+ mShowPreview = false;
+ importURL = KURL();
+}
+
+void XXPortManager::importVCard( const QString &vCard, bool showPreview )
+{
+ importData = vCard;
+ mShowPreview = showPreview;
+ slotImport( "vcard", "<empty>" );
+ mShowPreview = false;
+ importData = "";
+}
+
+void XXPortManager::slotImport( const QString &identifier, const QString &data )
+{
+ XXPortObject *obj = mXXPortObjects[ identifier ];
+ if ( !obj ) {
+ KMessageBox::error( mCore, i18n( "<qt>No import plugin available for <b>%1</b>.</qt>" ).arg( identifier ) );
+ return;
+ }
+
+ KABC::Resource *resource = mCore->requestResource( mCore );
+ if ( !resource )
+ return;
+
+ KABC::AddresseeList list = obj->importContacts( data );
+ KABC::AddresseeList::Iterator it;
+ bool imported = false;
+ for ( it = list.begin(); it != list.end(); ++it ) {
+ if ( mShowPreview ) {
+ PreviewDialog dlg( *it, mCore );
+ if ( !dlg.exec() )
+ continue;
+ }
+
+ (*it).setResource( resource );
+ // We use a PwNewCommand so the user can undo it.
+ PwNewCommand *command = new PwNewCommand( mCore->addressBook(), *it );
+ UndoStack::instance()->push( command );
+ RedoStack::instance()->clear();
+ imported = true;
+ }
+
+ if ( imported ) {
+ KMessageBox::information( mCore, i18n( "contacts successfully imported." ) );
+
+ emit modified();
+ }
+}
+
+void XXPortManager::slotExport( const QString &identifier, const QString &data )
+{
+ XXPortObject *obj = mXXPortObjects[ identifier ];
+ if ( !obj ) {
+ KMessageBox::error( mCore, i18n( "<qt>No export plugin available for <b>%1</b>.</qt>" ).arg( identifier ) );
+ return;
+ }
+
+ KABC::AddresseeList addrList;
+ XXPortSelectDialog dlg( mCore, obj->requiresSorting(), mCore );
+ if ( dlg.exec() )
+ addrList = dlg.contacts();
+ else
+ return;
+
+ if ( !obj->exportContacts( addrList, data ) )
+ KMessageBox::error( mCore, i18n( "Unable to export contacts." ) );
+ else
+ KMessageBox::information( mCore, i18n( "contacts successfully exported." ) );
+}
+
+void XXPortManager::loadPlugins()
+{
+ mXXPortObjects.clear();
+
+#ifndef KAB_EMBEDDED
+ KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/XXPort" );
+ KTrader::OfferList::ConstIterator it;
+ for ( it = plugins.begin(); it != plugins.end(); ++it ) {
+ if ( !(*it)->hasServiceType( "KAddressBook/XXPort" ) )
+ continue;
+
+ KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() );
+ if ( !factory ) {
+ kdDebug(5720) << "XXPortManager::loadExtensions(): Factory creation failed" << endl;
+ continue;
+ }
+
+ XXPortFactory *xxportFactory = static_cast<XXPortFactory*>( factory );
+
+ if ( !xxportFactory ) {
+ kdDebug(5720) << "XXPortManager::loadExtensions(): Cast failed" << endl;
+ continue;
+ }
+
+ XXPortObject *obj = xxportFactory->xxportObject( mCore->addressBook(), mCore );
+ if ( obj ) {
+ mCore->addGUIClient( obj );
+ mXXPortObjects.insert( obj->identifier(), obj );
+ connect( obj, SIGNAL( exportActivated( const QString&, const QString& ) ),
+ this, SLOT( slotExport( const QString&, const QString& ) ) );
+ connect( obj, SIGNAL( importActivated( const QString&, const QString& ) ),
+ this, SLOT( slotImport( const QString&, const QString& ) ) );
+ }
+ }
+
+#else //KAB_EMBEDDED
+//lets load the export/import stubs directly. Is dynamic loading necessary for KA/Pi?
+
+ // CVS import/export
+ XXPortFactory *xxportFactory = new CSVXXPortFactory();
+
+ XXPortObject *obj = xxportFactory->xxportObject( mCore->addressBook(), mCore );
+ if ( obj ) {
+ mCore->addGUIClient( obj );
+ mXXPortObjects.insert( obj->identifier(), obj );
+ connect( obj, SIGNAL( exportActivated( const QString&, const QString& ) ),
+ this, SLOT( slotExport( const QString&, const QString& ) ) );
+ connect( obj, SIGNAL( importActivated( const QString&, const QString& ) ),
+ this, SLOT( slotImport( const QString&, const QString& ) ) );
+ }
+
+
+
+ // KDE2 import/export
+ xxportFactory = new KDE2XXPortFactory();
+
+ obj = xxportFactory->xxportObject( mCore->addressBook(), mCore );
+ if ( obj ) {
+ mCore->addGUIClient( obj );
+ mXXPortObjects.insert( obj->identifier(), obj );
+ connect( obj, SIGNAL( exportActivated( const QString&, const QString& ) ),
+ this, SLOT( slotExport( const QString&, const QString& ) ) );
+ connect( obj, SIGNAL( importActivated( const QString&, const QString& ) ),
+ this, SLOT( slotImport( const QString&, const QString& ) ) );
+ }
+
+
+
+ // VCARD import/export
+ xxportFactory = new VCardXXPortFactory();
+
+ obj = xxportFactory->xxportObject( mCore->addressBook(), mCore );
+ if ( obj ) {
+ mCore->addGUIClient( obj );
+ mXXPortObjects.insert( obj->identifier(), obj );
+ connect( obj, SIGNAL( exportActivated( const QString&, const QString& ) ),
+ this, SLOT( slotExport( const QString&, const QString& ) ) );
+ connect( obj, SIGNAL( importActivated( const QString&, const QString& ) ),
+ this, SLOT( slotImport( const QString&, const QString& ) ) );
+ }
+#endif //KAB_EMBEDDED
+
+}
+
+
+PreviewDialog::PreviewDialog( const KABC::Addressee &addr, QWidget *parent,
+ const char *name )
+ : KDialogBase( Plain, i18n( "Contact Preview" ), Ok | Cancel, Ok, parent,
+ name, true, true )
+{
+ QWidget *page = plainPage();
+ QVBoxLayout *layout = new QVBoxLayout( page, marginHint(), spacingHint() );
+
+ KPIM::AddresseeView *view = new KPIM::AddresseeView( page );
+ view->setAddressee( addr );
+
+ layout->addWidget( view );
+
+ resize( 400, 300 );
+}
+
+#ifndef KAB_EMBEDDED
+#include "xxportmanager.moc"
+#endif //KAB_EMBEDDED
+
diff --git a/kaddressbook/xxportmanager.h b/kaddressbook/xxportmanager.h
new file mode 100644
index 0000000..f8436ed
--- a/dev/null
+++ b/kaddressbook/xxportmanager.h
@@ -0,0 +1,79 @@
+/*
+ This file is part of KAddressbook.
+ Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+/*
+Enhanced Version of the file for platform independent KDE tools.
+Copyright (c) 2004 Ulf Schenk
+
+$Id$
+*/
+
+
+#ifndef XXPORTMANAGER_H
+#define XXPORTMANAGER_H
+
+#include <qdict.h>
+#include <qobject.h>
+
+#include <kurl.h>
+
+#include "xxportobject.h"
+
+class KABCore;
+
+class XXPortManager : public QObject
+{
+ Q_OBJECT
+
+ public:
+ XXPortManager( KABCore *core, QObject *parent, const char *name = 0 );
+ ~XXPortManager();
+
+ void restoreSettings();
+ void saveSettings();
+
+ static KURL importURL;
+ static QString importData;
+
+ public slots:
+ void importVCard( const KURL &url );
+ void importVCard( const KURL &url, bool showPreview );
+ void importVCard( const QString &vCard, bool showPreview );
+
+ signals:
+ void modified();
+
+ protected slots:
+ void slotImport( const QString&, const QString& );
+ void slotExport( const QString&, const QString& );
+
+ private:
+ void loadPlugins();
+
+ QDict<XXPortObject> mXXPortObjects;
+
+ KABCore *mCore;
+ bool mShowPreview;
+};
+
+#endif
diff --git a/kaddressbook/xxportobject.cpp b/kaddressbook/xxportobject.cpp
new file mode 100644
index 0000000..42ab0fb
--- a/dev/null
+++ b/kaddressbook/xxportobject.cpp
@@ -0,0 +1,152 @@
+/*
+ This file is part of KAddressbook.
+ Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+/*
+Enhanced Version of the file for platform independent KDE tools.
+Copyright (c) 2004 Ulf Schenk
+
+$Id$
+*/
+
+#include <qmap.h>
+#include <qsignalmapper.h>
+
+#include <kaction.h>
+#include <kmessagebox.h>
+
+#include "kabcore.h"
+
+#include "xxportobject.h"
+
+class XXPortObject::XXPortObjectPrivate
+{
+ public:
+ QSignalMapper *mExportMapper;
+ QSignalMapper *mImportMapper;
+};
+
+XXPortObject::XXPortObject( KABC::AddressBook *ab, QWidget *parent,
+ const char *name )
+ : QObject( parent, name ), mAddressBook( ab ), mParentWidget( parent ),
+ d( new XXPortObjectPrivate )
+{
+ d->mExportMapper = new QSignalMapper( this );
+ d->mImportMapper = new QSignalMapper( this );
+
+ connect( d->mExportMapper, SIGNAL( mapped( const QString& ) ),
+ SLOT( slotExportActivated( const QString& ) ) );
+ connect( d->mImportMapper, SIGNAL( mapped( const QString& ) ),
+ SLOT( slotImportActivated( const QString& ) ) );
+}
+
+XXPortObject::~XXPortObject()
+{
+ delete d;
+ d = 0;
+}
+
+bool XXPortObject::exportContacts( const KABC::AddresseeList&, const QString& )
+{
+ // do nothing
+ return false;
+}
+
+KABC::AddresseeList XXPortObject::importContacts( const QString& ) const
+{
+ // do nothing
+ return KABC::AddresseeList();
+}
+
+void XXPortObject::createImportAction( const QString &label, const QString &data )
+{
+#ifdef KAB_EMBEDDED
+ KABCore* kabcore = (KABCore*)mParentWidget;
+#endif //KAB_EMBEDDED
+
+ QString id = "file_import_" + identifier() + ( data.isEmpty() ? QString( "" ) : "_" + data );
+#ifndef KAB_EMBEDDED
+ KAction *action = new KAction( label, 0, d->mImportMapper, SLOT( map() ), actionCollection(), id.latin1() );
+#else //KAB_EMBEDDED
+ KAction *action = new KAction( label, 0, d->mImportMapper, SLOT( map() ), kabcore->actionCollection(), id.latin1() );
+#endif //KAB_EMBEDDED
+
+ d->mImportMapper->setMapping( action, ( data.isEmpty() ? QString( "<empty>" ) : data ) );
+
+#ifndef KAB_EMBEDDED
+ setXMLFile( identifier() + "_xxportui.rc" );
+#endif //KAB_EMBEDDED
+
+#ifdef KAB_EMBEDDED
+ action->plug((QWidget*)kabcore->getImportMenu());
+#endif //KAB_EMBEDDED
+
+}
+
+void XXPortObject::createExportAction( const QString &label, const QString &data )
+{
+#ifdef KAB_EMBEDDED
+ KABCore* kabcore = (KABCore*)mParentWidget;
+#endif //KAB_EMBEDDED
+
+ QString id = "file_export_" + identifier() + ( data.isEmpty() ? QString( "" ) : "_" + data );
+#ifndef KAB_EMBEDDED
+ KAction *action = new KAction( label, 0, d->mExportMapper, SLOT( map() ), actionCollection(), id.latin1() );
+#else //KAB_EMBEDDED
+ KAction *action = new KAction( label, 0, d->mExportMapper, SLOT( map() ), kabcore->actionCollection(), id.latin1() );
+#endif //KAB_EMBEDDED
+
+ d->mExportMapper->setMapping( action, ( data.isEmpty() ? QString( "<empty>" ) : data ) );
+
+#ifndef KAB_EMBEDDED
+ setXMLFile( identifier() + "_xxportui.rc" );
+#endif //KAB_EMBEDDED
+
+#ifdef KAB_EMBEDDED
+ action->plug((QWidget*)kabcore->getExportMenu());
+#endif //KAB_EMBEDDED
+
+}
+
+KABC::AddressBook *XXPortObject::addressBook() const
+{
+ return mAddressBook;
+}
+
+QWidget *XXPortObject::parentWidget() const
+{
+ return mParentWidget;
+}
+
+void XXPortObject::slotExportActivated( const QString &data )
+{
+ emit exportActivated( identifier(), ( data == "<empty>" ? QString::null : data ) );
+}
+
+void XXPortObject::slotImportActivated( const QString &data )
+{
+ emit importActivated( identifier(), ( data == "<empty>" ? QString::null : data ) );
+}
+
+#ifndef KAB_EMBEDDED
+#include "xxportobject.moc"
+#endif //KAB_EMBEDDED
diff --git a/kaddressbook/xxportobject.h b/kaddressbook/xxportobject.h
new file mode 100644
index 0000000..d697700
--- a/dev/null
+++ b/kaddressbook/xxportobject.h
@@ -0,0 +1,157 @@
+/*
+ This file is part of KAddressbook.
+ Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+/*
+Enhanced Version of the file for platform independent KDE tools.
+Copyright (c) 2004 Ulf Schenk
+
+$Id$
+*/
+
+#ifndef XXPORTOBJECT_H
+#define XXPORTOBJECT_H
+
+#include <qobject.h>
+
+#include <kabc/addressbook.h>
+#include <kabc/addresseelist.h>
+#include <kxmlguiclient.h>
+#ifndef KAB_EMBEDDED
+#include <klibloader.h>
+#endif //KAB_EMBEDDED
+
+
+class XXPortObject : public QObject, virtual public KXMLGUIClient
+{
+ Q_OBJECT
+
+ public:
+ XXPortObject( KABC::AddressBook *ab, QWidget *parent, const char *name = 0 );
+ ~XXPortObject();
+
+ /**
+ Returns the unique identifier of this xxport modul, it should
+ be the lowercase name of the import/export format e.g. 'vcard'
+ */
+ virtual QString identifier() const = 0;
+
+ /**
+ Reimplement this method if the XXPortManager shall
+ pass a sorted list to @ref exportContacts().
+ */
+ virtual bool requiresSorting() const { return false; }
+
+ public slots:
+ /**
+ Reimplement this method for exporting the contacts.
+ */
+ virtual bool exportContacts( const KABC::AddresseeList &list, const QString& identifier );
+
+ /**
+ Reimplement this method for importing the contacts.
+ */
+ virtual KABC::AddresseeList importContacts( const QString& identifier ) const;
+
+ signals:
+ /**
+ Emitted whenever the export action is activated.
+ The parameter contains the @ref identifier() for
+ unique identification.
+ */
+ void exportActivated( const QString&, const QString& );
+
+ /**
+ Emitted whenever the import action is activated.
+ The parameter contains the @ref identifier() for
+ unique identification.
+ */
+ void importActivated( const QString&, const QString& );
+
+ protected:
+ /**
+ Create the import action. The identifier is passed in the import slot.
+ */
+ void createImportAction( const QString &label, const QString &identifier = QString::null );
+
+ /**
+ Create the export action. The identifier is passed in the export slot.
+ */
+ void createExportAction( const QString &label, const QString &identifier = QString::null );
+
+ /**
+ Returns a pointer to the address book object.
+ */
+ KABC::AddressBook *addressBook() const;
+
+ /**
+ Returns a pointer to the parent widget. It can be used as parent for
+ message boxes.
+ */
+ QWidget *parentWidget() const;
+
+
+ private slots:
+ void slotImportActivated( const QString& );
+ void slotExportActivated( const QString& );
+
+ private:
+ KABC::AddressBook *mAddressBook;
+ QWidget *mParentWidget;
+
+ class XXPortObjectPrivate;
+ XXPortObjectPrivate *d;
+};
+
+#ifndef KAB_EMBEDDED
+class XXPortFactory : public KLibFactory
+{
+ public:
+ virtual XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent,
+ const char *name = 0 ) = 0;
+
+ protected:
+ virtual QObject* createObject( QObject*, const char*, const char*,
+ const QStringList & )
+ {
+ return 0;
+ }
+};
+
+#else //KAB_EMBEDDED
+class XXPortFactory
+{
+ public:
+ virtual XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent,
+ const char *name = 0 ) = 0;
+
+ protected:
+ virtual QObject* createObject( QObject*, const char*, const char*,
+ const QStringList & )
+ {
+ return 0;
+ }
+};
+#endif //KAB_EMBEDDED
+
+
+#endif
diff --git a/kaddressbook/xxportselectdialog.cpp b/kaddressbook/xxportselectdialog.cpp
new file mode 100644
index 0000000..e0da3b2
--- a/dev/null
+++ b/kaddressbook/xxportselectdialog.cpp
@@ -0,0 +1,279 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Anders Lund <anders.lund@lund.tdcadsl.dk>
+ Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+/*
+Enhanced Version of the file for platform independent KDE tools.
+Copyright (c) 2004 Ulf Schenk
+
+$Id$
+*/
+
+#include <kabc/addressbook.h>
+#include <kapplication.h>
+#include <kcombobox.h>
+#include <klocale.h>
+#include <kglobal.h>
+
+#include <qbuttongroup.h>
+#include <qcombobox.h>
+#include <qheader.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qlistview.h>
+#include <qpushbutton.h>
+#include <qradiobutton.h>
+#include <qstringlist.h>
+#include <qwhatsthis.h>
+
+#include "kabcore.h"
+#include "kabprefs.h"
+
+#include "xxportselectdialog.h"
+
+XXPortSelectDialog::XXPortSelectDialog( KABCore *core, bool sort,
+ QWidget* parent, const char* name )
+ : KDialogBase( Plain, i18n( "Choose which contacts to export" ), Help | Ok | Cancel,
+ Ok, parent, name, true, true ), mCore( core ),
+ mUseSorting( sort )
+{
+ initGUI();
+
+ connect( mFiltersCombo, SIGNAL( activated( int ) ),
+ SLOT( filterChanged( int ) ) );
+ connect( mCategoriesView, SIGNAL( clicked( QListViewItem* ) ),
+ SLOT( categoryClicked( QListViewItem* ) ) );
+
+ // setup filters
+#ifndef KAB_EMBEDDED
+ mFilters = Filter::restore( kapp->config(), "Filter" );
+ Filter::List::iterator filterIt;
+#else //KAB_EMBEDDED
+ mFilters = Filter::restore( KGlobal::config(), "Filter" );
+ Filter::List::Iterator filterIt;
+#endif //KAB_EMBEDDED
+ QStringList filters;
+ for ( filterIt = mFilters.begin(); filterIt != mFilters.end(); ++filterIt )
+ filters.append( (*filterIt).name() );
+
+ mFiltersCombo->insertStringList( filters );
+ mUseFilters->setEnabled( filters.count() > 0 );
+
+ // setup categories
+ QStringList categories = KABPrefs::instance()->mCustomCategories;
+ QStringList::Iterator it;
+ for ( it = categories.begin(); it != categories.end(); ++it )
+ new QCheckListItem( mCategoriesView, *it, QCheckListItem::CheckBox );
+ mUseCategories->setEnabled( categories.count() > 0 );
+
+ int count = mCore->selectedUIDs().count();
+ mUseSelection->setEnabled( count != 0 );
+ mUseSelection->setChecked( count > 1 );
+
+ mSortTypeCombo->insertItem( i18n( "Ascending" ) );
+ mSortTypeCombo->insertItem( i18n( "Descending" ) );
+
+ mFields = mCore->addressBook()->fields( KABC::Field::All );
+ KABC::Field::List::Iterator fieldIt;
+ for ( fieldIt = mFields.begin(); fieldIt != mFields.end(); ++fieldIt )
+ mFieldCombo->insertItem( (*fieldIt)->label() );
+}
+
+KABC::AddresseeList XXPortSelectDialog::contacts()
+{
+ QStringList selection = mCore->selectedUIDs();
+
+ KABC::AddresseeList list;
+ if ( mUseSelection->isChecked() ) {
+ QStringList::Iterator it;
+ for ( it = selection.begin(); it != selection.end(); ++it ) {
+ KABC::Addressee addr = mCore->addressBook()->findByUid( *it );
+ if ( !addr.isEmpty() )
+ list.append( addr );
+ }
+ } else if ( mUseFilters->isChecked() ) {
+ // find contacts that can pass selected filter
+ Filter::List::Iterator filterIt;
+ for ( filterIt = mFilters.begin(); filterIt != mFilters.end(); ++filterIt )
+ if ( (*filterIt).name() == mFiltersCombo->currentText() )
+ break;
+
+ KABC::AddressBook::Iterator it;
+ for ( it = mCore->addressBook()->begin(); it != mCore->addressBook()->end(); ++it ) {
+ if ( (*filterIt).filterAddressee( *it ) )
+ list.append( *it );
+ }
+ } else if ( mUseCategories->isChecked() ) {
+ QStringList categorieList = categories();
+ KABC::AddressBook::Iterator it;
+ for ( it = mCore->addressBook()->begin(); it != mCore->addressBook()->end(); ++it ) {
+ QStringList tmp( (*it).categories() );
+ QStringList::Iterator tmpIt;
+ for ( tmpIt = tmp.begin(); tmpIt != tmp.end(); ++tmpIt )
+ if ( categorieList.contains( *tmpIt ) ) {
+ list.append( *it );
+ break;
+ }
+ }
+ } else {
+ // create a string list of all entries:
+ KABC::AddressBook::Iterator it;
+ for ( it = mCore->addressBook()->begin(); it != mCore->addressBook()->end(); ++it )
+ list.append( *it );
+ }
+
+ if ( mUseSorting ) {
+ list.setReverseSorting( mSortTypeCombo->currentItem() == 1 );
+ uint pos = mFieldCombo->currentItem();
+ if ( pos < mFields.count() )
+ list.sortByField( mFields[ pos ] );
+ }
+
+ return list;
+}
+
+QStringList XXPortSelectDialog::categories() const
+{
+ QStringList list;
+
+ QListViewItemIterator it( mCategoriesView );
+ for ( ; it.current(); ++it ) {
+ QCheckListItem* qcli = static_cast<QCheckListItem*>(it.current());
+ if ( qcli->isOn() )
+ list.append( it.current()->text( 0 ) );
+ }
+
+ return list;
+}
+
+void XXPortSelectDialog::filterChanged( int )
+{
+ mUseFilters->setChecked( true );
+}
+
+void XXPortSelectDialog::categoryClicked( QListViewItem *i )
+{
+ QCheckListItem *qcli = static_cast<QCheckListItem*>( i );
+ if ( qcli->isOn() )
+ mUseCategories->setChecked( true );
+}
+
+void XXPortSelectDialog::slotHelp()
+{
+#ifndef KAB_EMBEDDED
+ kapp->invokeHelp( "import-and-export" );
+#else //KAB_EMBEDDED
+ qDebug("XXPortSelectDialog::slotHelp is not implemented yet");
+#endif //KAB_EMBEDDED
+
+}
+
+void XXPortSelectDialog::initGUI()
+{
+ QFrame *page = plainPage();
+
+ QVBoxLayout *topLayout = new QVBoxLayout( page, KDialog::marginHint(),
+ KDialog::spacingHint() );
+
+ QLabel *label = new QLabel( i18n( "Which contacts do you want to export?" ), page );
+ topLayout->addWidget( label );
+
+ mButtonGroup = new QButtonGroup( i18n( "Selection" ), page );
+ mButtonGroup->setColumnLayout( 0, Qt::Vertical );
+ mButtonGroup->layout()->setSpacing( KDialog::spacingHint() );
+ mButtonGroup->layout()->setMargin( KDialog::marginHint() );
+
+ QGridLayout *groupLayout = new QGridLayout( mButtonGroup->layout() );
+ groupLayout->setAlignment( Qt::AlignTop );
+
+ mUseWholeBook = new QRadioButton( i18n( "&All contacts" ), mButtonGroup );
+ mUseWholeBook->setChecked( true );
+ QWhatsThis::add( mUseWholeBook, i18n( "Export the entire address book" ) );
+ groupLayout->addWidget( mUseWholeBook, 0, 0 );
+
+ mUseSelection = new QRadioButton( i18n( "&Selected contacts" ), mButtonGroup );
+ QWhatsThis::add( mUseSelection, i18n( "Only export contacts selected in KAddressBook.\n"
+ "This option is disabled if no contacts are selected." ) );
+ groupLayout->addWidget( mUseSelection, 1, 0 );
+
+ mUseFilters = new QRadioButton( i18n( "Contacts matching &filter" ), mButtonGroup );
+ QWhatsThis::add( mUseFilters, i18n( "Only export contacts matching the selected filter.\n"
+ "This option is disabled if you haven't defined any filters" ) );
+ groupLayout->addWidget( mUseFilters, 2, 0 );
+
+ mUseCategories = new QRadioButton( i18n( "Category &members" ), mButtonGroup );
+ QWhatsThis::add( mUseCategories, i18n( "Only export contacts who are members of a category that is checked on the list to the left.\n"
+ "This option is disabled if you have no categories." ) );
+ groupLayout->addWidget( mUseCategories, 3, 0 );
+
+ mFiltersCombo = new QComboBox( false, mButtonGroup );
+ QWhatsThis::add( mFiltersCombo, i18n( "Select a filter to decide which contacts to export." ) );
+ groupLayout->addWidget( mFiltersCombo, 2, 1 );
+
+ mCategoriesView = new QListView( mButtonGroup );
+ mCategoriesView->addColumn( "" );
+ mCategoriesView->header()->hide();
+ QWhatsThis::add( mCategoriesView, i18n( "Check the categories whose members you want to export." ) );
+ groupLayout->addWidget( mCategoriesView, 3, 1 );
+
+ topLayout->addWidget( mButtonGroup );
+
+ QButtonGroup *sortingGroup = new QButtonGroup( i18n( "Sorting" ), page );
+ sortingGroup->setColumnLayout( 0, Qt::Vertical );
+ QGridLayout *sortLayout = new QGridLayout( sortingGroup->layout(), 2, 2,
+ KDialog::spacingHint() );
+ sortLayout->setAlignment( Qt::AlignTop );
+
+ label = new QLabel( i18n( "Criterion:" ), sortingGroup );
+ sortLayout->addWidget( label, 0, 0 );
+
+#ifndef KAB_EMBEDDED
+ mFieldCombo = new KComboBox( false, sortingGroup );
+#else //KAB_EMBEDDED
+ //US Combobox is not editable anyway
+ mFieldCombo = new KComboBox( sortingGroup );
+#endif //KAB_EMBEDDED
+ sortLayout->addWidget( mFieldCombo, 0, 1 );
+
+ label = new QLabel( i18n( "Order:" ), sortingGroup );
+ sortLayout->addWidget( label, 1, 0 );
+
+#ifndef KAB_EMBEDDED
+ mSortTypeCombo = new KComboBox( false, sortingGroup );
+#else //KAB_EMBEDDED
+ //US Combobox is not editable anyway
+ mSortTypeCombo = new KComboBox( sortingGroup );
+#endif //KAB_EMBEDDED
+ sortLayout->addWidget( mSortTypeCombo, 1, 1 );
+
+ topLayout->addWidget( sortingGroup );
+
+ if ( !mUseSorting )
+ sortingGroup->hide();
+}
+
+#ifndef KAB_EMBEDDED
+#include "xxportselectdialog.moc"
+#endif //KAB_EMBEDDED
+
+
diff --git a/kaddressbook/xxportselectdialog.h b/kaddressbook/xxportselectdialog.h
new file mode 100644
index 0000000..8d56f66
--- a/dev/null
+++ b/kaddressbook/xxportselectdialog.h
@@ -0,0 +1,81 @@
+/*
+ This file is part of KAddressBook.
+ Copyright (c) 2002 Anders Lund <anders.lund@lund.tdcadsl.dk>
+ Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+#ifndef XXPORTSELECTDIALOG_H
+#define XXPORTSELECTDIALOG_H
+
+#include <kabc/addresseelist.h>
+#include <kabc/field.h>
+#include <kdialogbase.h>
+
+#include "filter.h"
+
+class QButtonGroup;
+class QComboBox;
+class QListView;
+class QListViewItem;
+class QRadioButton;
+
+class KABCore;
+class KComboBox;
+
+class XXPortSelectDialog : public KDialogBase
+{
+ Q_OBJECT
+
+ public:
+ XXPortSelectDialog( KABCore *core, bool sort, QWidget* parent,
+ const char* name = 0 );
+
+ KABC::AddresseeList contacts();
+
+ private slots:
+ void filterChanged( int );
+ void categoryClicked( QListViewItem * i );
+
+ protected slots:
+ void slotHelp();
+
+ private:
+ void initGUI();
+ QStringList categories() const;
+
+ QButtonGroup* mButtonGroup;
+ QRadioButton* mUseCategories;
+ QRadioButton* mUseFilters;
+ QRadioButton* mUseWholeBook;
+ QRadioButton* mUseSelection;
+ QComboBox* mFiltersCombo;
+ QListView* mCategoriesView;
+
+ KComboBox *mFieldCombo;
+ KComboBox *mSortTypeCombo;
+
+ KABCore *mCore;
+ KABC::AddresseeList mAddresseeList;
+ Filter::List mFilters;
+ KABC::Field::List mFields;
+ bool mUseSorting;
+};
+
+#endif