author | zautrix <zautrix> | 2005-03-31 11:26:51 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-03-31 11:26:51 (UTC) |
commit | c0fa26aa3b33c293853bdd7d028ddb0545e33c85 (patch) (side-by-side diff) | |
tree | 12bbb65fb6d235415bd7a7007c1e019ccfcf97ac /kaddressbook | |
parent | f39d5000ed2f9a436ee94cbd42f840651afa89d6 (diff) | |
download | kdepimpi-c0fa26aa3b33c293853bdd7d028ddb0545e33c85.zip kdepimpi-c0fa26aa3b33c293853bdd7d028ddb0545e33c85.tar.gz kdepimpi-c0fa26aa3b33c293853bdd7d028ddb0545e33c85.tar.bz2 |
many fixes
-rw-r--r-- | kaddressbook/emaileditwidget.cpp | 2 | ||||
-rw-r--r-- | kaddressbook/phoneeditwidget.cpp | 27 |
2 files changed, 27 insertions, 2 deletions
diff --git a/kaddressbook/emaileditwidget.cpp b/kaddressbook/emaileditwidget.cpp index 0e01b02..e72face 100644 --- a/kaddressbook/emaileditwidget.cpp +++ b/kaddressbook/emaileditwidget.cpp @@ -1,275 +1,277 @@ /* 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 ); + mEmailEdit->setFocus(); #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() ); + mEmailListBox->removeItem( mEmailListBox->currentItem() ); 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/phoneeditwidget.cpp b/kaddressbook/phoneeditwidget.cpp index 19bb676..a435959 100644 --- a/kaddressbook/phoneeditwidget.cpp +++ b/kaddressbook/phoneeditwidget.cpp @@ -1,530 +1,553 @@ /* 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(); + KABC::PhoneNumber::List list = dlg.phoneNumbers(); + setPhoneNumbers( list ); updateCombos(); updateLineEdits(); 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() ); } 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 ) { +#ifdef DESKTOP_VERSION + setRenameEnabled ( 0, true ); +#endif 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() ) { + QListViewItem* i = mListView->firstChild(); KABC::PhoneNumber phoneNumber = dlg.phoneNumber(); + bool insert = true; + while ( i ) { + PhoneViewItem* p = ( PhoneViewItem* ) i; + KABC::PhoneNumber pn = p->phoneNumber(); + if ( (pn.type() | KABC::PhoneNumber::Pref) == (phoneNumber.type() | KABC::PhoneNumber::Pref) ) { + if ( p->text(0).isEmpty()) { + p->setPhoneNumber( phoneNumber ); + mPhoneNumberList.remove( pn ); + mPhoneNumberList.append( phoneNumber ); + insert = false; + break; + } + } + i = i->nextSibling(); + } + if ( insert ) { 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 ); + mNumber->setFocus(); + mNumber->setSelection( 0, 1024); } 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 |