diff --git a/akonadi/contact/editor/addresseditwidget.cpp b/akonadi/contact/editor/addresseditwidget.cpp index 8ff067e3e..cb153cc6f 100644 --- a/akonadi/contact/editor/addresseditwidget.cpp +++ b/akonadi/contact/editor/addresseditwidget.cpp @@ -1,621 +1,621 @@ /* - This file is part of KContactManager. + This file is part of KAddressBook. Copyright (c) 2009 Tobias Koenig 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 "addresseditwidget.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include class TabPressEater : public QObject { public: TabPressEater( QObject *parent ) : QObject( parent ) { setObjectName( "TabPressEater" ); } protected: bool eventFilter( QObject*, QEvent *event ) { if ( event->type() == QEvent::KeyPress ) { QKeyEvent *keyEvent = (QKeyEvent*)event; if ( keyEvent->key() == Qt::Key_Tab ) { QApplication::sendEvent( parent(), event ); return true; } else return false; } else { return false; } } }; /** * Dialog for creating a new address types. * * @note This dialog is only used by AddressTypeCombo. */ class AddressTypeDialog : public KDialog { public: AddressTypeDialog( KABC::Address::Type type, QWidget *parent ); ~AddressTypeDialog(); KABC::Address::Type type() const; private: QButtonGroup *mGroup; KABC::Address::TypeList mTypeList; }; AddressSelectionWidget::AddressSelectionWidget( QWidget *parent ) : KComboBox( parent ) { connect( this, SIGNAL( activated( int ) ), SLOT( selected( int ) ) ); } AddressSelectionWidget::~AddressSelectionWidget() { } void AddressSelectionWidget::setAddresses( const KABC::Address::List &addresses ) { mAddresses = addresses; updateView(); } void AddressSelectionWidget::setCurrentAddress( const KABC::Address &address ) { const int index = mAddresses.indexOf( address ); if ( index != -1 ) setCurrentIndex( index ); } KABC::Address AddressSelectionWidget::currentAddress() const { if ( currentIndex() != -1 && currentIndex() < mAddresses.count() ) return mAddresses.at( currentIndex() ); else return KABC::Address(); } void AddressSelectionWidget::selected( int index ) { Q_ASSERT( index != -1 && index < mAddresses.count() ); emit selectionChanged( mAddresses.at( index ) ); } void AddressSelectionWidget::updateView() { clear(); for ( int i = 0; i < mAddresses.count(); ++i ) addItem( KABC::Address::typeLabel( mAddresses.at( i ).type() ) ); } AddressTypeCombo::AddressTypeCombo( QWidget *parent ) : KComboBox( parent ), mType( KABC::Address::Home ), mLastSelected( 0 ) { for ( int i = 0; i < KABC::Address::typeList().count(); ++i ) mTypeList.append( KABC::Address::typeList().at( i ) ); mTypeList.append( -1 ); // Others... update(); connect( this, SIGNAL( activated( int ) ), this, SLOT( selected( int ) ) ); } AddressTypeCombo::~AddressTypeCombo() { } void AddressTypeCombo::setType( KABC::Address::Type type ) { if ( !mTypeList.contains( (int)type ) ) { // insert at the end, but before the 'Others...' entry mTypeList.insert( mTypeList.at( mTypeList.count() - 1 ), (int)type ); } mType = type; update(); } KABC::Address::Type AddressTypeCombo::type() const { return mType; } void AddressTypeCombo::update() { bool blocked = signalsBlocked(); blockSignals( true ); clear(); for ( int i = 0; i < mTypeList.count(); ++i ) { if ( mTypeList.at( i ) == -1 ) // "Other..." entry addItem( i18nc( "@item:inlistbox Category of contact info field", "Other..." ) ); else addItem( KABC::Address::typeLabel( KABC::Address::Type( mTypeList.at( i ) ) ) ); } setCurrentIndex( mLastSelected = mTypeList.indexOf( mType ) ); blockSignals( blocked ); } void AddressTypeCombo::selected( int pos ) { if ( mTypeList.at( pos ) == -1 ) otherSelected(); else { mType = KABC::Address::Type( mTypeList.at( pos ) ); mLastSelected = pos; } } void AddressTypeCombo::otherSelected() { AddressTypeDialog dlg( mType, this ); if ( dlg.exec() ) { mType = dlg.type(); if ( !mTypeList.contains( mType ) ) mTypeList.insert( mTypeList.at( mTypeList.count() - 1 ), mType ); } else { setType( KABC::Address::Type( mTypeList.at( mLastSelected ) ) ); } update(); } AddressEditWidget::AddressEditWidget( QWidget *parent ) : QWidget( parent ), mReadOnly( false ) { QGridLayout *layout = new QGridLayout( this ); layout->setSpacing( 2 ); layout->setMargin( 4 ); layout->setSpacing( KDialog::spacingHint() ); mAddressSelectionWidget = new AddressSelectionWidget( this ); connect( mAddressSelectionWidget, SIGNAL( selectionChanged( const KABC::Address& ) ), SLOT( updateAddressView() ) ); layout->addWidget( mAddressSelectionWidget, 0, 0, 1, 3 ); mAddressView = new QLabel( this ); mAddressView->setFrameStyle( QFrame::Panel | QFrame::Sunken ); mAddressView->setMinimumHeight( 20 ); mAddressView->setAlignment( Qt::AlignTop ); mAddressView->setTextFormat( Qt::PlainText ); mAddressView->setTextInteractionFlags( Qt::TextSelectableByKeyboard | Qt::TextSelectableByMouse ); layout->addWidget( mAddressView, 1, 0, 1, 3 ); mCreateButton = new QPushButton( i18nc( "street/postal", "New..." ), this ); connect( mCreateButton, SIGNAL( clicked() ), this, SLOT( createAddress() ) ); mEditButton = new QPushButton( i18nc( "street/postal", "Edit..." ), this ); connect( mEditButton, SIGNAL( clicked() ), this, SLOT( editAddress() ) ); mDeleteButton = new QPushButton( i18nc( "street/postal", "Delete" ), this ); connect( mDeleteButton, SIGNAL( clicked() ), this, SLOT( deleteAddress() ) ); layout->addWidget( mCreateButton, 2, 0 ); layout->addWidget( mEditButton, 2, 1 ); layout->addWidget( mDeleteButton, 2, 2 ); updateButtons(); } AddressEditWidget::~AddressEditWidget() { } void AddressEditWidget::setReadOnly( bool readOnly ) { mReadOnly = readOnly; updateButtons(); } void AddressEditWidget::updateName( const QString &name ) { mName = name; updateAddressView(); } void AddressEditWidget::createAddress() { AddressEditDialog dialog( this ); if ( dialog.exec() ) { const KABC::Address address = dialog.address(); fixPreferredAddress( address ); mAddressList.append( address ); mAddressSelectionWidget->setAddresses( mAddressList ); mAddressSelectionWidget->setCurrentAddress( address ); updateAddressView(); updateButtons(); } } void AddressEditWidget::editAddress() { AddressEditDialog dialog( this ); dialog.setAddress( mAddressSelectionWidget->currentAddress() ); if ( dialog.exec() ) { const KABC::Address address = dialog.address(); fixPreferredAddress( address ); mAddressList[ mAddressSelectionWidget->currentIndex() ] = address; mAddressSelectionWidget->setAddresses( mAddressList ); mAddressSelectionWidget->setCurrentAddress( address ); updateAddressView(); } } void AddressEditWidget::deleteAddress() { const int result = KMessageBox::questionYesNo( this, i18n( "Do you really want to delete this address?" ) ); if ( result != KMessageBox::Yes ) return; mAddressList.removeAt( mAddressSelectionWidget->currentIndex() ); mAddressSelectionWidget->setAddresses( mAddressList ); updateAddressView(); updateButtons(); } void AddressEditWidget::fixPreferredAddress( const KABC::Address &preferredAddress ) { // as the preferred address is mutual exclusive, we have to // remove the flag from all other addresses if ( preferredAddress.type() & KABC::Address::Pref ) { for ( int i = 0; i < mAddressList.count(); ++i ) { KABC::Address &address = mAddressList[ i ]; address.setType( address.type() & ~KABC::Address::Pref ); } } } void AddressEditWidget::updateAddressView() { const KABC::Address address = mAddressSelectionWidget->currentAddress(); if ( address.isEmpty() ) mAddressView->setText( QString() ); else mAddressView->setText( address.formattedAddress( mName ) ); } void AddressEditWidget::updateButtons() { mCreateButton->setEnabled( !mReadOnly ); mEditButton->setEnabled( !mReadOnly && (mAddressList.count() > 0) ); mDeleteButton->setEnabled( !mReadOnly && (mAddressList.count() > 0) ); } void AddressEditWidget::loadContact( const KABC::Addressee &contact ) { mName = contact.realName(); mAddressList = contact.addresses(); mAddressSelectionWidget->setAddresses( mAddressList ); // set the preferred address as the visible one for ( int i = 0; i < mAddressList.count(); ++i ) { if ( mAddressList.at( i ).type() & KABC::Address::Pref ) { mAddressSelectionWidget->setCurrentAddress( mAddressList.at( i ) ); break; } } updateAddressView(); updateButtons(); } void AddressEditWidget::storeContact( KABC::Addressee &contact ) const { // delete all previous addresses const KABC::Address::List oldAddresses = contact.addresses(); for ( int i = 0; i < oldAddresses.count(); ++i ) contact.removeAddress( oldAddresses.at( i ) ); // insert the new ones for ( int i = 0; i < mAddressList.count(); ++i ) { const KABC::Address address( mAddressList.at( i ) ); if ( !address.isEmpty() ) contact.insertAddress( address ); } } AddressEditDialog::AddressEditDialog( QWidget *parent ) : KDialog(parent) { setCaption( i18nc( "street/postal", "Edit Address" ) ); setButtons( Ok | Cancel ); setDefaultButton( Ok ); showButtonSeparator( true ); QWidget *page = new QWidget( this ); setMainWidget( page ); QGridLayout *topLayout = new QGridLayout( page ); topLayout->setSpacing( spacingHint() ); topLayout->setMargin( 0 ); mTypeCombo = new AddressTypeCombo( page ); topLayout->addWidget( mTypeCombo, 0, 0, 1, 2 ); QLabel *label = new QLabel( i18nc( ":", "%1:", KABC::Address::streetLabel() ), page ); label->setAlignment( Qt::AlignTop | Qt::AlignLeft ); topLayout->addWidget( label, 1, 0 ); mStreetTextEdit = new KTextEdit( page ); mStreetTextEdit->setAcceptRichText( false ); label->setBuddy( mStreetTextEdit ); topLayout->addWidget( mStreetTextEdit, 1, 1 ); TabPressEater *eater = new TabPressEater( this ); mStreetTextEdit->installEventFilter( eater ); label = new QLabel( i18nc( ":", "%1:", KABC::Address::postOfficeBoxLabel() ), page ); topLayout->addWidget( label, 2 , 0 ); mPOBoxEdit = new KLineEdit( page ); label->setBuddy( mPOBoxEdit ); topLayout->addWidget( mPOBoxEdit, 2, 1 ); label = new QLabel( i18nc( ":", "%1:", KABC::Address::localityLabel() ), page ); topLayout->addWidget( label, 3, 0 ); mLocalityEdit = new KLineEdit( page ); label->setBuddy( mLocalityEdit ); topLayout->addWidget( mLocalityEdit, 3, 1 ); label = new QLabel( i18nc( ":", "%1:", KABC::Address::regionLabel() ), page ); topLayout->addWidget( label, 4, 0 ); mRegionEdit = new KLineEdit( page ); label->setBuddy( mRegionEdit ); topLayout->addWidget( mRegionEdit, 4, 1 ); label = new QLabel( i18nc( ":", "%1:", KABC::Address::postalCodeLabel() ), page ); topLayout->addWidget( label, 5, 0 ); mPostalCodeEdit = new KLineEdit( page ); label->setBuddy( mPostalCodeEdit ); topLayout->addWidget( mPostalCodeEdit, 5, 1 ); label = new QLabel( i18nc( ":", "%1:", KABC::Address::countryLabel() ), page ); topLayout->addWidget( label, 6, 0 ); mCountryCombo = new KComboBox( page ); mCountryCombo->setEditable( true ); mCountryCombo->setDuplicatesEnabled( false ); QPushButton *labelButton = new QPushButton( i18n( "Edit Label..." ), page ); topLayout->addWidget( labelButton, 7, 0, 1, 2 ); connect( labelButton, SIGNAL( clicked() ), SLOT( editLabel() ) ); fillCountryCombo(); label->setBuddy( mCountryCombo ); topLayout->addWidget( mCountryCombo, 6, 1 ); mPreferredCheckBox = new QCheckBox( i18nc( "street/postal", "This is the preferred address" ), page ); topLayout->addWidget( mPreferredCheckBox, 8, 0, 1, 2 ); KSeparator *sep = new KSeparator( Qt::Horizontal, page ); topLayout->addWidget( sep, 9, 0, 1, 2 ); KHBox *buttonBox = new KHBox( page ); buttonBox->setSpacing( spacingHint() ); topLayout->addWidget( buttonBox, 10, 0, 1, 2 ); KAcceleratorManager::manage( this ); } AddressEditDialog::~AddressEditDialog() { } void AddressEditDialog::editLabel() { bool ok = false; QString result = KInputDialog::getMultiLineText( KABC::Address::labelLabel(), KABC::Address::labelLabel(), mLabel, &ok, this ); if ( ok ) mLabel = result; } void AddressEditDialog::setAddress(const KABC::Address &address) { mAddress = address; mTypeCombo->setType( mAddress.type() ); mStreetTextEdit->setPlainText( mAddress.street() ); mRegionEdit->setText( mAddress.region() ); mLocalityEdit->setText( mAddress.locality() ); mPostalCodeEdit->setText( mAddress.postalCode() ); mPOBoxEdit->setText( mAddress.postOfficeBox() ); mLabel = mAddress.label(); mPreferredCheckBox->setChecked( mAddress.type() & KABC::Address::Pref ); if ( mAddress.isEmpty() ) mCountryCombo->setItemText( mCountryCombo->currentIndex(), KGlobal::locale()->countryCodeToName( KGlobal::locale()->country() ) ); else mCountryCombo->setItemText( mCountryCombo->currentIndex(), mAddress.country() ); mStreetTextEdit->setFocus(); } KABC::Address AddressEditDialog::address() const { KABC::Address address( mAddress ); address.setType( mTypeCombo->type() ); address.setLocality( mLocalityEdit->text() ); address.setRegion( mRegionEdit->text() ); address.setPostalCode( mPostalCodeEdit->text() ); address.setCountry( mCountryCombo->currentText() ); address.setPostOfficeBox( mPOBoxEdit->text() ); address.setStreet( mStreetTextEdit->toPlainText() ); address.setLabel( mLabel ); if ( mPreferredCheckBox->isChecked() ) { address.setType( address.type() | KABC::Address::Pref ); } else address.setType( address.type() & ~(KABC::Address::Pref) ); return address; } void AddressEditDialog::fillCountryCombo() { QStringList countries; foreach( const QString &cc, KGlobal::locale()->allCountriesList() ) { countries.append( KGlobal::locale()->countryCodeToName(cc) ); } countries = sortLocaleAware( countries ); mCountryCombo->addItems( countries ); mCountryCombo->completionObject()->setItems( countries ); mCountryCombo->setAutoCompletion( true ); } AddressTypeDialog::AddressTypeDialog( KABC::Address::Type type, QWidget *parent ) : KDialog( parent) { setCaption( i18nc( "street/postal", "Edit Address Type" ) ); setButtons( Ok | Cancel ); setDefaultButton( Ok ); QWidget *page = new QWidget(this); setMainWidget( page ); QVBoxLayout *layout = new QVBoxLayout( page ); layout->setSpacing( KDialog::spacingHint() ); layout->setMargin( 0 ); QGroupBox *box = new QGroupBox( i18nc( "street/postal", "Address Types" ), page ); layout->addWidget( box ); mGroup = new QButtonGroup( box ); mGroup->setExclusive ( false ); QGridLayout *buttonLayout = new QGridLayout( box ); mTypeList = KABC::Address::typeList(); mTypeList.removeAll( KABC::Address::Pref ); KABC::Address::TypeList::ConstIterator it; int i = 0; int row = 0; for ( it = mTypeList.constBegin(); it != mTypeList.constEnd(); ++it, ++i ) { QCheckBox *cb = new QCheckBox( KABC::Address::typeLabel( *it ), box ); cb->setChecked( type & mTypeList[ i ] ); buttonLayout->addWidget( cb, row, i%3 ); if( i%3 == 2 ) ++row; mGroup->addButton( cb ); } } AddressTypeDialog::~AddressTypeDialog() { } KABC::Address::Type AddressTypeDialog::type() const { KABC::Address::Type type; for ( int i = 0; i < mGroup->buttons().count(); ++i ) { QCheckBox *box = dynamic_cast( mGroup->buttons().at( i ) ); if ( box && box->isChecked() ) type |= mTypeList[ i ]; } return type; } /** Small helper class, I hope we can remove it as soon as a general solution has been committed to kdelibs */ class LocaleAwareString : public QString { public: LocaleAwareString() : QString() {} LocaleAwareString( const QString &str ) : QString( str ) {} }; static bool operator<( const LocaleAwareString &s1, const LocaleAwareString &s2 ) { return ( QString::localeAwareCompare( s1, s2 ) < 0 ); } QStringList AddressEditDialog::sortLocaleAware( const QStringList &list ) { QList sortedList; QStringList::ConstIterator it; for ( it = list.constBegin(); it != list.constEnd(); ++it ) sortedList.append( LocaleAwareString( *it ) ); qSort( sortedList.begin(), sortedList.end() ); QStringList retval; QList::ConstIterator retIt; for ( retIt = sortedList.constBegin(); retIt != sortedList.constEnd(); ++retIt ) retval.append( *retIt ); return retval; } #include "addresseditwidget.moc" diff --git a/akonadi/contact/editor/addresseditwidget.h b/akonadi/contact/editor/addresseditwidget.h index d11db865b..2c235b82f 100644 --- a/akonadi/contact/editor/addresseditwidget.h +++ b/akonadi/contact/editor/addresseditwidget.h @@ -1,211 +1,211 @@ /* - This file is part of KContactManager. + This file is part of KAddressBook. Copyright (c) 2009 Tobias Koenig 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 #include #include #include #include class QCheckBox; class QLabel; class KLineEdit; class KTextEdit; /** * @short A widget that shows a list of addresses for selection. */ class AddressSelectionWidget : public KComboBox { Q_OBJECT public: /** * Creates a new address selection widget. * * @param parent The parent widget. */ AddressSelectionWidget( QWidget *parent = 0 ); /** * Destroys the address selection widget. */ virtual ~AddressSelectionWidget(); /** * Sets the list of @p addresses that can be chosen from. */ void setAddresses( const KABC::Address::List &addresses ); /** * Sets the current @p address. */ void setCurrentAddress( const KABC::Address &address ); /** * Returns the current selected address. */ KABC::Address currentAddress() const; Q_SIGNALS: /** * This signal is emitted whenever the selection of the * address has changed. * * @param address The new selected address. */ void selectionChanged( const KABC::Address &address ); private Q_SLOTS: void selected( int ); private: void updateView(); KABC::Address::List mAddresses; }; /** * @short A widget for selecting the type of an address. */ class AddressTypeCombo : public KComboBox { Q_OBJECT public: /** * Creates a new address type combo. * * @param parent The parent widget. */ AddressTypeCombo( QWidget *parent = 0 ); /** * Destroys the address type combo. */ ~AddressTypeCombo(); /** * Sets the type that shall be selected in the combobox. */ void setType( KABC::Address::Type type ); /** * Returns the type that is currently selected. */ KABC::Address::Type type() const; private Q_SLOTS: void selected( int ); void otherSelected(); private: void update(); KABC::Address::Type mType; int mLastSelected; QList mTypeList; }; /** * @short An editor widget for addresses. */ class AddressEditWidget : public QWidget { Q_OBJECT public: explicit AddressEditWidget( QWidget *parent = 0 ); ~AddressEditWidget(); void loadContact( const KABC::Addressee &contact ); void storeContact( KABC::Addressee &contact ) const; void setReadOnly( bool readOnly ); public Q_SLOTS: void updateName( const QString &name ); private Q_SLOTS: void updateAddressView(); void createAddress(); void editAddress(); void deleteAddress(); private: void updateButtons(); void fixPreferredAddress( const KABC::Address &preferredAddress ); AddressSelectionWidget *mAddressSelectionWidget; QLabel *mAddressView; QPushButton *mCreateButton; QPushButton *mEditButton; QPushButton *mDeleteButton; KABC::Address::List mAddressList; QString mName; bool mReadOnly; }; /** Dialog for editing address details. */ class AddressEditDialog : public KDialog { Q_OBJECT public: AddressEditDialog( QWidget *parent = 0 ); ~AddressEditDialog(); void setAddress( const KABC::Address &address ); KABC::Address address() const; private Q_SLOTS: void editLabel(); private: void fillCountryCombo(); QStringList sortLocaleAware( const QStringList& ); AddressTypeCombo *mTypeCombo; KTextEdit *mStreetTextEdit; KComboBox *mCountryCombo; KLineEdit *mRegionEdit; KLineEdit *mLocalityEdit; KLineEdit *mPostalCodeEdit; KLineEdit *mPOBoxEdit; QCheckBox *mPreferredCheckBox; KABC::Address mAddress; QString mLabel; }; #endif diff --git a/akonadi/contact/editor/contacteditor.cpp b/akonadi/contact/editor/contacteditor.cpp index b8836737d..55a901938 100644 --- a/akonadi/contact/editor/contacteditor.cpp +++ b/akonadi/contact/editor/contacteditor.cpp @@ -1,533 +1,533 @@ /* - This file is part of KContactManager. + This file is part of KAddressBook. Copyright (c) 2009 Tobias Koenig 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "contacteditor.h" #include "addresseditwidget.h" #include "contactmetadata.h" #include "dateeditwidget.h" #include "displaynameeditwidget.h" #include "emaileditwidget.h" #include "freebusyeditwidget.h" #include "imagewidget.h" #include "imeditwidget.h" #include "nameeditwidget.h" #include "phoneeditwidget.h" #include "soundeditwidget.h" #include #include #include #include #include #include #include #include #include #include class ContactEditor::Private { public: Private( ContactEditor *parent ) : mParent( parent ) { } void initGui(); void initGuiContactTab(); void initGuiLocationTab(); void initGuiBusinessTab(); void initGuiPersonalTab(); QString loadCustom( const KABC::Addressee &contact, const QString &key ) const; void storeCustom( KABC::Addressee &contact, const QString &key, const QString &value ) const; ContactEditor *mParent; KTabWidget *mTabWidget; // widgets from name group NameEditWidget *mNameWidget; ImageWidget *mPhotoWidget; DisplayNameEditWidget *mDisplayNameWidget; KLineEdit *mNickNameWidget; SoundEditWidget *mPronunciationWidget; // widgets from internet group EmailEditWidget *mEmailWidget; KLineEdit *mHomepageWidget; KLineEdit *mBlogWidget; IMEditWidget *mIMWidget; // widgets from phones group PhoneEditWidget *mPhonesWidget; // widgets from addresses group AddressEditWidget *mAddressesWidget; // widgets from coordinates group QWidget *mCoordinatesWidget; // widgets from general group ImageWidget *mLogoWidget; KLineEdit *mOrganizationWidget; KLineEdit *mProfessionWidget; KLineEdit *mTitleWidget; KLineEdit *mDepartmentWidget; KLineEdit *mOfficeWidget; KLineEdit *mManagerWidget; KLineEdit *mAssistantWidget; // widgets from groupware group FreeBusyEditWidget *mFreeBusyWidget; // widgets from notes group KTextEdit *mNotesWidget; // widgets from dates group DateEditWidget *mBirthdateWidget; DateEditWidget *mAnniversaryWidget; // widgets from family group KLineEdit *mPartnerWidget; }; void ContactEditor::Private::initGui() { QVBoxLayout *layout = new QVBoxLayout( mParent ); layout->setMargin( 0 ); mTabWidget = new KTabWidget( mParent ); layout->addWidget( mTabWidget ); initGuiContactTab(); initGuiLocationTab(); initGuiBusinessTab(); initGuiPersonalTab(); } void ContactEditor::Private::initGuiContactTab() { QWidget *widget = new QWidget; QVBoxLayout *layout = new QVBoxLayout( widget ); mTabWidget->addTab( widget, i18n( "Contact" ) ); QGroupBox *nameGroupBox = new QGroupBox( i18n( "Name" ) ); QGroupBox *internetGroupBox = new QGroupBox( i18n( "Internet" ) ); QGroupBox *phonesGroupBox = new QGroupBox( i18n( "Phones" ) ); layout->addWidget( nameGroupBox ); layout->addWidget( internetGroupBox ); layout->addWidget( phonesGroupBox ); QGridLayout *nameLayout = new QGridLayout( nameGroupBox ); QGridLayout *internetLayout = new QGridLayout( internetGroupBox ); QGridLayout *phonesLayout = new QGridLayout( phonesGroupBox ); QLabel *label = 0; // setup name group box label = new QLabel( i18n( "Name:" ) ); label->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); nameLayout->addWidget( label, 0, 0 ); mNameWidget = new NameEditWidget; label->setBuddy( mNameWidget ); nameLayout->addWidget( mNameWidget, 0, 1 ); mPhotoWidget = new ImageWidget( ImageWidget::Photo ); mPhotoWidget->setMinimumSize( QSize( 100, 140 ) ); nameLayout->addWidget( mPhotoWidget, 0, 2, 4, 1 ); label = new QLabel( i18n( "Display:" ) ); label->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); nameLayout->addWidget( label, 1, 0 ); mDisplayNameWidget = new DisplayNameEditWidget; label->setBuddy( mDisplayNameWidget ); nameLayout->addWidget( mDisplayNameWidget, 1, 1 ); label = new QLabel( i18n( "Nickname:" ) ); label->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); nameLayout->addWidget( label, 2, 0 ); mNickNameWidget = new KLineEdit; label->setBuddy( mNickNameWidget ); nameLayout->addWidget( mNickNameWidget, 2, 1 ); label = new QLabel( i18n( "Pronunciation:" ) ); label->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); nameLayout->addWidget( label, 3, 0 ); mPronunciationWidget = new SoundEditWidget; label->setBuddy( mPronunciationWidget ); nameLayout->addWidget( mPronunciationWidget, 3, 1 ); nameLayout->setRowStretch( 4, 1 ); // setup internet group box label = new QLabel( i18n( "Email:" ) ); label->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); internetLayout->addWidget( label, 0, 0 ); mEmailWidget = new EmailEditWidget; label->setBuddy( mEmailWidget ); internetLayout->addWidget( mEmailWidget, 0, 1 ); label = new QLabel( i18n( "Homepage:" ) ); label->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); internetLayout->addWidget( label, 1, 0 ); mHomepageWidget = new KLineEdit; label->setBuddy( mHomepageWidget ); internetLayout->addWidget( mHomepageWidget, 1, 1 ); label = new QLabel( i18n( "Blog:" ) ); label->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); internetLayout->addWidget( label, 2, 0 ); mBlogWidget = new KLineEdit; label->setBuddy( mBlogWidget ); internetLayout->addWidget( mBlogWidget, 2, 1 ); label = new QLabel( i18n( "Messaging:" ) ); label->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); internetLayout->addWidget( label, 3, 0 ); mIMWidget = new IMEditWidget; label->setBuddy( mIMWidget ); internetLayout->addWidget( mIMWidget, 3, 1 ); internetLayout->setRowStretch( 4, 1 ); // setup phones group box mPhonesWidget = new PhoneEditWidget; phonesLayout->addWidget( mPhonesWidget, 0, 0 ); phonesLayout->setRowStretch( 1, 1 ); } void ContactEditor::Private::initGuiLocationTab() { QWidget *widget = new QWidget; QVBoxLayout *layout = new QVBoxLayout( widget ); mTabWidget->addTab( widget, i18n( "Location" ) ); QGroupBox *addressesGroupBox = new QGroupBox( i18n( "Addresses" ) ); QGroupBox *coordinatesGroupBox = new QGroupBox( i18n( "Coordinates" ) ); layout->addWidget( addressesGroupBox ); layout->addWidget( coordinatesGroupBox ); QGridLayout *addressesLayout = new QGridLayout( addressesGroupBox ); QGridLayout *coordinatesLayout = new QGridLayout( coordinatesGroupBox ); // setup addresses group box mAddressesWidget = new AddressEditWidget( addressesGroupBox ); mAddressesWidget->setMinimumHeight( 200 ); addressesLayout->addWidget( mAddressesWidget, 0, 0 ); addressesLayout->setRowStretch( 1, 1 ); // setup coordinates group box mCoordinatesWidget = new QWidget; coordinatesLayout->addWidget( mCoordinatesWidget, 0, 0 ); coordinatesLayout->setRowStretch( 1, 1 ); } void ContactEditor::Private::initGuiBusinessTab() { QWidget *widget = new QWidget; QVBoxLayout *layout = new QVBoxLayout( widget ); mTabWidget->addTab( widget, i18n( "Business" ) ); QGroupBox *generalGroupBox = new QGroupBox( i18n( "General" ) ); QGroupBox *groupwareGroupBox = new QGroupBox( i18n( "Groupware" ) ); QGroupBox *notesGroupBox = new QGroupBox( i18n( "Notes" ) ); layout->addWidget( generalGroupBox ); layout->addWidget( groupwareGroupBox ); layout->addWidget( notesGroupBox ); QGridLayout *generalLayout = new QGridLayout( generalGroupBox ); QGridLayout *groupwareLayout = new QGridLayout( groupwareGroupBox ); QGridLayout *notesLayout = new QGridLayout( notesGroupBox ); QLabel *label = 0; // setup general group box mLogoWidget = new ImageWidget( ImageWidget::Logo ); generalLayout->addWidget( mLogoWidget, 0, 2, 6, 1, Qt::AlignTop ); label = new QLabel( i18n( "Organization:" ) ); label->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); generalLayout->addWidget( label, 0, 0 ); mOrganizationWidget = new KLineEdit; label->setBuddy( mOrganizationWidget ); generalLayout->addWidget( mOrganizationWidget, 0, 1 ); label = new QLabel( i18n( "Profession:" ) ); label->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); generalLayout->addWidget( label, 1, 0 ); mProfessionWidget = new KLineEdit; label->setBuddy( mProfessionWidget ); generalLayout->addWidget( mProfessionWidget, 1, 1 ); label = new QLabel( i18n( "Title:" ) ); label->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); generalLayout->addWidget( label, 2, 0 ); mTitleWidget = new KLineEdit; label->setBuddy( mTitleWidget ); generalLayout->addWidget( mTitleWidget , 2, 1 ); label = new QLabel( i18n( "Department:" ) ); label->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); generalLayout->addWidget( label, 3, 0 ); mDepartmentWidget = new KLineEdit; label->setBuddy( mDepartmentWidget ); generalLayout->addWidget( mDepartmentWidget, 3, 1 ); label = new QLabel( i18n( "Office:" ) ); label->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); generalLayout->addWidget( label, 4, 0 ); mOfficeWidget = new KLineEdit; label->setBuddy( mOfficeWidget ); generalLayout->addWidget( mOfficeWidget, 4, 1 ); label = new QLabel( i18n( "Manager's name:" ) ); label->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); generalLayout->addWidget( label, 5, 0 ); mManagerWidget = new KLineEdit; label->setBuddy( mManagerWidget ); generalLayout->addWidget( mManagerWidget, 5, 1 ); label = new QLabel( i18n( "Assistant's name:" ) ); label->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); generalLayout->addWidget( label, 6, 0 ); mAssistantWidget = new KLineEdit; label->setBuddy( mAssistantWidget ); generalLayout->addWidget( mAssistantWidget, 6, 1 ); generalLayout->setRowStretch( 7, 1 ); // setup groupware group box label = new QLabel( i18n( "Free/Busy:" ) ); label->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); groupwareLayout->addWidget( label, 0, 0 ); mFreeBusyWidget = new FreeBusyEditWidget; label->setBuddy( mFreeBusyWidget ); groupwareLayout->addWidget( mFreeBusyWidget, 0, 1 ); groupwareLayout->setRowStretch( 1, 1 ); // setup notes group box mNotesWidget = new KTextEdit; notesLayout->addWidget( mNotesWidget, 0, 0 ); } void ContactEditor::Private::initGuiPersonalTab() { QWidget *widget = new QWidget; QVBoxLayout *layout = new QVBoxLayout( widget ); mTabWidget->addTab( widget, i18n( "Personal" ) ); QGroupBox *datesGroupBox = new QGroupBox( i18n( "Dates" ) ); QGroupBox *familyGroupBox = new QGroupBox( i18n( "Family" ) ); layout->addWidget( datesGroupBox ); layout->addWidget( familyGroupBox ); QGridLayout *datesLayout = new QGridLayout( datesGroupBox ); QGridLayout *familyLayout = new QGridLayout( familyGroupBox ); QLabel *label = 0; // setup dates group box label = new QLabel( i18n( "Birthdate:" ) ); label->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); datesLayout->addWidget( label, 0, 0 ); mBirthdateWidget = new DateEditWidget; label->setBuddy( mBirthdateWidget ); datesLayout->addWidget( mBirthdateWidget, 0, 1 ); label = new QLabel( i18n( "Anniversary:" ) ); label->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); datesLayout->addWidget( label, 1, 0 ); mAnniversaryWidget = new DateEditWidget; label->setBuddy( mAnniversaryWidget ); datesLayout->addWidget( mAnniversaryWidget, 1, 1 ); datesLayout->setRowStretch( 2, 1 ); datesLayout->setColumnStretch( 1, 1 ); // widgets from family group label = new QLabel( i18n( "Partner's name:" ) ); label->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); familyLayout->addWidget( label, 0, 0 ); mPartnerWidget = new KLineEdit; label->setBuddy( mPartnerWidget ); familyLayout->addWidget( mPartnerWidget, 0, 1 ); familyLayout->setRowStretch( 1, 1 ); } QString ContactEditor::Private::loadCustom( const KABC::Addressee &contact, const QString &key ) const { return contact.custom( "KADDRESSBOOK", key ); } void ContactEditor::Private::storeCustom( KABC::Addressee &contact, const QString &key, const QString &value ) const { if ( value.isEmpty() ) contact.removeCustom( "KADDRESSBOOK", key ); else contact.insertCustom( "KADDRESSBOOK", key, value ); } ContactEditor::ContactEditor( QWidget* ) : d( new Private( this ) ) { d->initGui(); connect( d->mNameWidget, SIGNAL( nameChanged( const KABC::Addressee& ) ), d->mDisplayNameWidget, SLOT( changeName( const KABC::Addressee& ) ) ); connect( d->mOrganizationWidget, SIGNAL( textChanged( const QString& ) ), d->mDisplayNameWidget, SLOT( changeOrganization( const QString& ) ) ); } ContactEditor::~ContactEditor() { delete d; } void ContactEditor::loadContact( const KABC::Addressee &contact ) { // name group d->mPhotoWidget->loadContact( contact ); d->mNameWidget->loadContact( contact ); d->mDisplayNameWidget->loadContact( contact ); d->mNickNameWidget->setText( contact.nickName() ); d->mPronunciationWidget->loadContact( contact ); // internet group d->mEmailWidget->loadContact( contact ); d->mHomepageWidget->setUrl( contact.url() ); d->mBlogWidget->setText( d->loadCustom( contact, "BlogFeed" ) ); d->mIMWidget->loadContact( contact ); // phones group d->mPhonesWidget->loadContact( contact ); // address group d->mAddressesWidget->loadContact( contact ); // coordinates group // general group d->mLogoWidget->loadContact( contact ); d->mOrganizationWidget->setText( contact.organization() ); d->mProfessionWidget->setText( d->loadCustom( contact, "X-Profession" ) ); d->mTitleWidget->setText( contact.title() ); d->mDepartmentWidget->setText( contact.department() ); d->mOfficeWidget->setText( d->loadCustom( contact, "X-Office" ) ); d->mManagerWidget->setText( d->loadCustom( contact, "X-ManagersName" ) ); d->mAssistantWidget->setText( d->loadCustom( contact, "X-AssistantsName" ) ); // groupware group d->mFreeBusyWidget->loadContact( contact ); // notes group d->mNotesWidget->setPlainText( contact.note() ); // dates group d->mBirthdateWidget->setDate( contact.birthday().date() ); d->mAnniversaryWidget->setDate( QDate::fromString( d->loadCustom( contact, "X-Anniversary" ), Qt::ISODate ) ); // family group d->mPartnerWidget->setText( d->loadCustom( contact, "X-SpousesName" ) ); const ContactMetaData metaData( contact ); d->mDisplayNameWidget->setDisplayType( (DisplayNameEditWidget::DisplayType)metaData.displayNameMode() ); } void ContactEditor::storeContact( KABC::Addressee &contact ) const { // name group d->mPhotoWidget->storeContact( contact ); d->mNameWidget->storeContact( contact ); d->mDisplayNameWidget->storeContact( contact ); contact.setNickName( d->mNickNameWidget->text().trimmed() ); d->mPronunciationWidget->storeContact( contact ); // internet group d->mEmailWidget->storeContact( contact ); contact.setUrl( KUrl( d->mHomepageWidget->text().trimmed() ) ); d->storeCustom( contact, "BlogFeed", d->mBlogWidget->text().trimmed() ); d->mIMWidget->storeContact( contact ); // phones group d->mPhonesWidget->storeContact( contact ); // address group d->mAddressesWidget->storeContact( contact ); // coordinates group // general group d->mLogoWidget->storeContact( contact ); contact.setOrganization( d->mOrganizationWidget->text() ); d->storeCustom( contact, "X-Profession", d->mProfessionWidget->text().trimmed() ); contact.setTitle( d->mTitleWidget->text().trimmed() ); contact.setDepartment( d->mDepartmentWidget->text().trimmed() ); d->storeCustom( contact, "X-Office", d->mOfficeWidget->text().trimmed() ); d->storeCustom( contact, "X-ManagersName", d->mManagerWidget->text().trimmed() ); d->storeCustom( contact, "X-AssistantsName", d->mAssistantWidget->text().trimmed() ); // groupware group d->mFreeBusyWidget->storeContact( contact ); // notes group contact.setNote( d->mNotesWidget->toPlainText() ); // dates group contact.setBirthday( QDateTime( d->mBirthdateWidget->date(), QTime() ) ); d->storeCustom( contact, "X-Anniversary", d->mAnniversaryWidget->date().toString( Qt::ISODate ) ); // family group d->storeCustom( contact, "X-SpousesName", d->mPartnerWidget->text().trimmed() ); ContactMetaData metaData( contact ); metaData.setDisplayNameMode( d->mDisplayNameWidget->displayType() ); } diff --git a/akonadi/contact/editor/contacteditor.h b/akonadi/contact/editor/contacteditor.h index 0766ea4a8..8abdd3f69 100644 --- a/akonadi/contact/editor/contacteditor.h +++ b/akonadi/contact/editor/contacteditor.h @@ -1,68 +1,68 @@ /* - This file is part of KContactManager. + This file is part of KAddressBook. Copyright (c) 2009 Tobias Koenig 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef CONTACTEDITOR_H #define CONTACTEDITOR_H #include "abstractcontacteditorwidget.h" namespace KABC { class Addressee; } /** * @short A widget for editing a contact. * * @author Tobias Koenig */ class ContactEditor : public AbstractContactEditorWidget { public: /** * Creates a new contact editor. * * @param parent The parent widget. */ ContactEditor( QWidget *parent = 0 ); /** * Destroys the contact editor. */ ~ContactEditor(); /** * Initializes the fields of the contact editor * with the values from a @p contact. */ void loadContact( const KABC::Addressee &contact ); /** * Stores back the fields of the contact editor * into the given @p contact. */ void storeContact( KABC::Addressee &contact ) const; private: class Private; Private* const d; }; #endif diff --git a/akonadi/contact/editor/dateeditwidget.cpp b/akonadi/contact/editor/dateeditwidget.cpp index 2ecfc039b..0b6e406cd 100644 --- a/akonadi/contact/editor/dateeditwidget.cpp +++ b/akonadi/contact/editor/dateeditwidget.cpp @@ -1,118 +1,118 @@ /* - This file is part of KContactManager. + This file is part of KAddressBook. Copyright (c) 2009 Tobias Koenig 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "dateeditwidget.h" #include #include #include #include #include #include #include #include #include #include DateLineEdit::DateLineEdit( QWidget *parent ) : KLineEdit( parent ) { setReadOnly( true ); } void DateLineEdit::contextMenuEvent( QContextMenuEvent *event ) { QMenu menu; menu.addAction( i18n( "Remove" ), this, SLOT( emitSignal() ) ); menu.exec( event->globalPos() ); } void DateLineEdit::emitSignal() { emit resetDate(); } DateEditWidget::DateEditWidget( QWidget *parent ) : QWidget( parent ) { QHBoxLayout *layout = new QHBoxLayout( this ); layout->setMargin( 0 ); mView = new DateLineEdit; layout->addWidget( mView ); mButton = new QToolButton; mButton->setPopupMode(QToolButton::InstantPopup); mButton->setIcon( KIcon( "view-calendar-day" ) ); layout->addWidget( mButton ); mMenu = new KPIM::KDatePickerPopup( KPIM::KDatePickerPopup::DatePicker, QDate(), this ); mButton->setMenu( mMenu ); connect( mMenu, SIGNAL( dateChanged( const QDate& ) ), SLOT( dateSelected( const QDate& ) ) ); connect( mView, SIGNAL( resetDate() ), SLOT( resetDate() ) ); updateView(); } DateEditWidget::~DateEditWidget() { } void DateEditWidget::setDate( const QDate &date ) { mDate = date; mMenu->setDate( mDate ); updateView(); } QDate DateEditWidget::date() const { return mDate; } void DateEditWidget::setReadOnly( bool readOnly ) { mButton->setEnabled( !readOnly ); } void DateEditWidget::dateSelected(const QDate &date) { mDate = date; updateView(); } void DateEditWidget::resetDate() { mDate = QDate(); updateView(); } void DateEditWidget::updateView() { if ( mDate.isValid() ) mView->setText( KGlobal::locale()->formatDate( mDate ) ); else mView->setText( QString() ); } #include "dateeditwidget.moc" diff --git a/akonadi/contact/editor/dateeditwidget.h b/akonadi/contact/editor/dateeditwidget.h index 6cbe5b6a6..f1f64daa4 100644 --- a/akonadi/contact/editor/dateeditwidget.h +++ b/akonadi/contact/editor/dateeditwidget.h @@ -1,79 +1,79 @@ /* - This file is part of KContactManager. + This file is part of KAddressBook. Copyright (c) 2009 Tobias Koenig 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef DATEEDITWIDGET_H #define DATEEDITWIDGET_H #include #include #include namespace KPIM { class KDatePickerPopup; } class QContextMenuEvent; class QToolButton; class DateLineEdit : public KLineEdit { Q_OBJECT public: DateLineEdit( QWidget *parent = 0 ); Q_SIGNALS: void resetDate(); protected: virtual void contextMenuEvent( QContextMenuEvent* ); private Q_SLOTS: void emitSignal(); }; class DateEditWidget : public QWidget { Q_OBJECT public: DateEditWidget( QWidget *parent = 0 ); ~DateEditWidget(); void setDate( const QDate &date ); QDate date() const; void setReadOnly( bool readOnly ); private Q_SLOTS: void dateSelected( const QDate& ); void resetDate(); void updateView(); private: QDate mDate; DateLineEdit *mView; QToolButton *mButton; KPIM::KDatePickerPopup *mMenu; }; #endif diff --git a/akonadi/contact/editor/displaynameeditwidget.cpp b/akonadi/contact/editor/displaynameeditwidget.cpp index 50621c7b1..1a518b30d 100644 --- a/akonadi/contact/editor/displaynameeditwidget.cpp +++ b/akonadi/contact/editor/displaynameeditwidget.cpp @@ -1,200 +1,200 @@ /* - This file is part of KContactManager. + This file is part of KAddressBook. Copyright (c) 2009 Tobias Koenig 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "displaynameeditwidget.h" #include #include #include #include #include #include #include #include #include #include class DisplayNameEditWidget::LineEdit : public KLineEdit { public: LineEdit( DisplayNameEditWidget *parent ) : KLineEdit( parent ), mParent( parent ) { } protected: // context menu handling virtual void contextMenuEvent( QContextMenuEvent *event ) { mParent->contextMenuEvent( event ); } private: DisplayNameEditWidget *mParent; }; DisplayNameEditWidget::DisplayNameEditWidget( QWidget *parent ) : QWidget( parent ), mDisplayType( FullName ) { QHBoxLayout *layout = new QHBoxLayout( this ); layout->setMargin( 0 ); layout->setSpacing( KDialog::spacingHint() ); mView = new LineEdit( this ); layout->addWidget( mView ); } DisplayNameEditWidget::~DisplayNameEditWidget() { } void DisplayNameEditWidget::setReadOnly( bool readOnly ) { mView->setReadOnly( readOnly && (mDisplayType != CustomName) ); } void DisplayNameEditWidget::setDisplayType( DisplayType type ) { mDisplayType = type; updateView(); } DisplayNameEditWidget::DisplayType DisplayNameEditWidget::displayType() const { return mDisplayType; } void DisplayNameEditWidget::loadContact( const KABC::Addressee &contact ) { mView->setText( contact.formattedName() ); mContact = contact; updateView(); } void DisplayNameEditWidget::storeContact( KABC::Addressee &contact ) const { contact.setFormattedName( mView->text() ); } void DisplayNameEditWidget::changeName( const KABC::Addressee &contact ) { const QString organization = mContact.organization(); mContact = contact; mContact.setOrganization( organization ); mContact.setFormattedName( mView->text() ); updateView(); } void DisplayNameEditWidget::changeOrganization( const QString &organization ) { mContact.setOrganization( organization ); updateView(); } void DisplayNameEditWidget::contextMenuEvent( QContextMenuEvent *event ) { QMenu menu; QActionGroup *group = new QActionGroup( this ); KToggleAction *simpleNameAction = new KToggleAction( i18n( "Simple Name" ), group ); KToggleAction *fullNameAction = new KToggleAction( i18n( "Full Name" ), group ); KToggleAction *reverseNameWithCommaAction = new KToggleAction( i18n( "Reverse Name with Comma" ), group ); KToggleAction *reverseNameAction = new KToggleAction( i18n( "Reverse Name" ), group ); KToggleAction *organizationNameAction = new KToggleAction( i18n( "Organization Name" ), group ); KToggleAction *customNameAction = new KToggleAction( i18n( "Custom" ), group ); group->setExclusive( true ); menu.addAction( simpleNameAction ); menu.addAction( fullNameAction ); menu.addAction( reverseNameWithCommaAction ); menu.addAction( reverseNameAction ); menu.addAction( organizationNameAction ); menu.addAction( customNameAction ); if ( mDisplayType == SimpleName ) simpleNameAction->setChecked( true ); if ( mDisplayType == FullName ) fullNameAction->setChecked( true ); if ( mDisplayType == ReverseNameWithComma ) reverseNameWithCommaAction->setChecked( true ); if ( mDisplayType == ReverseName ) reverseNameAction->setChecked( true ); if ( mDisplayType == Organization ) organizationNameAction->setChecked( true ); if ( mDisplayType == CustomName ) customNameAction->setChecked( true ); QAction *result = menu.exec( event->globalPos() ); if ( result == simpleNameAction ) mDisplayType = SimpleName; else if ( result == fullNameAction ) mDisplayType = FullName; else if ( result == reverseNameWithCommaAction ) mDisplayType = ReverseNameWithComma; else if ( result == reverseNameAction ) mDisplayType = ReverseName; else if ( result == organizationNameAction ) mDisplayType = Organization; else if ( result == customNameAction ) mDisplayType = CustomName; delete group; updateView(); } void DisplayNameEditWidget::updateView() { QString text; switch ( mDisplayType ) { case SimpleName: text = mContact.givenName() + ' ' + mContact.familyName(); break; case FullName: text = mContact.assembledName(); break; case ReverseNameWithComma: text = mContact.familyName() + ", " + mContact.givenName(); break; case ReverseName: text = mContact.familyName() + ' ' + mContact.givenName(); break; case Organization: text = mContact.organization(); break; case CustomName: text = mContact.formattedName(); default: break; } mView->setText( text ); mView->setReadOnly( mDisplayType != CustomName ); } #include "displaynameeditwidget.moc" diff --git a/akonadi/contact/editor/displaynameeditwidget.h b/akonadi/contact/editor/displaynameeditwidget.h index f004871b3..e6b5a727f 100644 --- a/akonadi/contact/editor/displaynameeditwidget.h +++ b/akonadi/contact/editor/displaynameeditwidget.h @@ -1,81 +1,81 @@ /* - This file is part of KContactManager. + This file is part of KAddressBook. Copyright (c) 2009 Tobias Koenig 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef DISPLAYNAMEEDITWIDGET_H #define DISPLAYNAMEEDITWIDGET_H #include #include /** * @short A widget for editing the display name of a contact. * * The widget will either use a predefined schema for formatting * the name or a custom one. */ class DisplayNameEditWidget : public QWidget { Q_OBJECT public: /** * Describes what the display name should look like. */ enum DisplayType { CustomName, ///< Let the user input a display name SimpleName, ///< A name of the form: givenName familyName FullName, ///< A name of the form: prefix givenName additionalName familyName suffix ReverseNameWithComma, ///< A name of the form: familyName, givenName ReverseName, ///< A name of the form: familyName givenName Organization ///< The organization name }; explicit DisplayNameEditWidget( QWidget *parent = 0 ); ~DisplayNameEditWidget(); void loadContact( const KABC::Addressee &contact ); void storeContact( KABC::Addressee &contact ) const; void setReadOnly( bool readOnly ); void setDisplayType( DisplayType type ); DisplayType displayType() const; public Q_SLOTS: void changeName( const KABC::Addressee &contact ); void changeOrganization( const QString &organization ); protected: // context menu handling virtual void contextMenuEvent( QContextMenuEvent* ); private: void updateView(); class LineEdit; LineEdit *mView; DisplayType mDisplayType; KABC::Addressee mContact; }; #endif diff --git a/akonadi/contact/editor/emaileditwidget.cpp b/akonadi/contact/editor/emaileditwidget.cpp index 491b76243..4ebf04ace 100644 --- a/akonadi/contact/editor/emaileditwidget.cpp +++ b/akonadi/contact/editor/emaileditwidget.cpp @@ -1,334 +1,334 @@ /* - This file is part of KContactManager. + This file is part of KAddressBook. Copyright (c) 2009 Tobias Koenig 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "emaileditwidget.h" #include #include #include #include #include #include #include #include #include #include #include #include #include class EmailValidator : public QRegExpValidator { public: EmailValidator() : QRegExpValidator( 0 ) { setObjectName( "EmailValidator" ); QRegExp rx( ".*@.*\\.[A-Za-z]+" ); setRegExp( rx ); } }; class EmailItem : public QListWidgetItem { public: EmailItem( const QString &text, QListWidget *parent, bool preferred ) : QListWidgetItem( text, parent ), mPreferred( preferred ) { format(); } void setPreferred( bool preferred ) { mPreferred = preferred; format(); } bool preferred() const { return mPreferred; } private: void format() { QFont f = font(); f.setBold( mPreferred ); setFont( f ); } private: bool mPreferred; }; EmailEditWidget::EmailEditWidget( QWidget *parent ) : QWidget( parent ) { QHBoxLayout *layout = new QHBoxLayout( this ); layout->setMargin( 0 ); layout->setSpacing( KDialog::spacingHint() ); mEmailEdit = new KLineEdit; mEmailEdit->setValidator( new EmailValidator ); connect( mEmailEdit, SIGNAL( textChanged( const QString& ) ), SLOT( textChanged( const QString& ) ) ); layout->addWidget( mEmailEdit ); mEditButton = new QToolButton; mEditButton->setText( "..." ); connect( mEditButton, SIGNAL( clicked() ), SLOT( edit() ) ); layout->addWidget( mEditButton ); } EmailEditWidget::~EmailEditWidget() { } void EmailEditWidget::setReadOnly( bool readOnly ) { mEmailEdit->setReadOnly( readOnly ); mEditButton->setEnabled( !readOnly ); } void EmailEditWidget::loadContact( const KABC::Addressee &contact ) { mEmailList = contact.emails(); if ( !mEmailList.isEmpty() ) mEmailEdit->setText( mEmailList.first() ); else mEmailEdit->setText( QString() ); } void EmailEditWidget::storeContact( KABC::Addressee &contact ) const { QStringList emails( mEmailList ); // the preferred address is always the first one, remove it... if ( !emails.isEmpty() ) emails.removeFirst(); // ... and prepend the one from the line edit if ( !mEmailEdit->text().isEmpty() ) emails.prepend( mEmailEdit->text() ); contact.setEmails( emails ); } void EmailEditWidget::edit() { EmailEditDialog dlg( mEmailList, this ); if ( dlg.exec() ) { if ( dlg.changed() ) { mEmailList = dlg.emails(); if ( !mEmailList.isEmpty() ) mEmailEdit->setText( mEmailList.first() ); else mEmailEdit->setText( QString() ); } } } void EmailEditWidget::textChanged( const QString &text ) { if ( !mEmailList.isEmpty() ) mEmailList.removeFirst(); mEmailList.prepend( text ); } EmailEditDialog::EmailEditDialog( const QStringList &list, QWidget *parent ) : KDialog( parent ) { setCaption( i18n( "Edit Email Addresses" ) ); setButtons( KDialog::Ok | KDialog::Cancel ); setDefaultButton( KDialog::Help ); QWidget *page = new QWidget( this); setMainWidget( page ); QGridLayout *topLayout = new QGridLayout( page ); topLayout->setSpacing( spacingHint() ); topLayout->setMargin( 0 ); mEmailListBox = new KListWidget( page ); mEmailListBox->setSelectionMode( QAbstractItemView::SingleSelection ); // Make sure there is room for the scrollbar mEmailListBox->setMinimumHeight( mEmailListBox->sizeHint().height() + 30 ); connect( mEmailListBox, SIGNAL( currentItemChanged( QListWidgetItem *, QListWidgetItem * ) ), SLOT( selectionChanged() ) ); connect( mEmailListBox, SIGNAL( itemDoubleClicked( QListWidgetItem * ) ), SLOT( edit() ) ); topLayout->addWidget( mEmailListBox, 0, 0, 5, 2 ); mAddButton = new QPushButton( i18n( "Add..." ), page ); connect( mAddButton, SIGNAL( clicked() ), SLOT( add() ) ); topLayout->addWidget( mAddButton, 0, 2 ); mEditButton = new QPushButton( i18n( "Edit..." ), page ); mEditButton->setEnabled( false ); connect( mEditButton, SIGNAL( clicked() ), SLOT( edit() ) ); topLayout->addWidget( mEditButton, 1, 2 ); mRemoveButton = new QPushButton( i18n( "Remove" ), page ); mRemoveButton->setEnabled( false ); connect( mRemoveButton, SIGNAL( clicked() ), SLOT( remove() ) ); topLayout->addWidget( mRemoveButton, 2, 2 ); mStandardButton = new QPushButton( i18n( "Set Standard" ), page ); mStandardButton->setEnabled( false ); connect( mStandardButton, SIGNAL( clicked() ), SLOT( standard() ) ); topLayout->addWidget( mStandardButton, 3, 2 ); topLayout->setRowStretch( 4, 1 ); QStringList items = list; if ( items.removeAll( "" ) > 0 ) mChanged = true; else mChanged = false; QStringList::ConstIterator it; bool preferred = true; for ( it = items.constBegin(); it != items.constEnd(); ++it ) { new EmailItem( *it, mEmailListBox, preferred ); preferred = false; } // set default state KAcceleratorManager::manage( this ); setInitialSize( QSize( 400, 200 ) ); } EmailEditDialog::~EmailEditDialog() { } QStringList EmailEditDialog::emails() const { QStringList emails; for ( int i = 0; i < mEmailListBox->count(); ++i ) { EmailItem *item = static_cast( mEmailListBox->item( i ) ); if ( item->preferred() ) emails.prepend( item->text() ); else emails.append( item->text() ); } return emails; } void EmailEditDialog::add() { EmailValidator *validator = new EmailValidator; bool ok = false; QString email = KInputDialog::getText( i18n( "Add Email" ), i18n( "New Email:" ), QString(), &ok, this, validator ); if ( !ok ) return; // check if item already available, ignore if so... for ( int i = 0; i < mEmailListBox->count(); ++i ) { if ( mEmailListBox->item( i )->text() == email ) return; } new EmailItem( email, mEmailListBox, (mEmailListBox->count() == 0) ); mChanged = true; } void EmailEditDialog::edit() { EmailValidator *validator = new EmailValidator; bool ok = false; QListWidgetItem *item = mEmailListBox->currentItem(); QString email = KInputDialog::getText( i18n( "Edit Email" ), i18nc( "@label:textbox Inputfield for an email address", "Email:" ), item->text(), &ok, this, validator ); if ( !ok ) return; // check if item already available, ignore if so... for ( int i = 0; i < mEmailListBox->count(); ++i ) { if ( mEmailListBox->item( i )->text() == email ) return; } EmailItem *eitem = static_cast( item ); eitem->setText( email ); mChanged = true; } void EmailEditDialog::remove() { QString address = mEmailListBox->currentItem()->text(); QString text = i18n( "Are you sure that you want to remove the email address %1?", address ); QString caption = i18n( "Confirm Remove" ); if ( KMessageBox::warningContinueCancel( this, text, caption, KGuiItem( i18n( "&Delete" ), "edit-delete" ) ) == KMessageBox::Continue ) { EmailItem *item = static_cast( mEmailListBox->currentItem() ); bool preferred = item->preferred(); mEmailListBox->takeItem( mEmailListBox->currentRow() ); if ( preferred ) { item = dynamic_cast( mEmailListBox->item( 0 ) ); if ( item ) item->setPreferred( true ); } mChanged = true; } } bool EmailEditDialog::changed() const { return mChanged; } void EmailEditDialog::standard() { for ( int i = 0; i < mEmailListBox->count(); ++i ) { EmailItem *item = static_cast( mEmailListBox->item( i ) ); if ( i == mEmailListBox->currentRow() ) item->setPreferred( true ); else item->setPreferred( false ); } mChanged = true; } void EmailEditDialog::selectionChanged() { int index = mEmailListBox->currentRow(); bool value = ( index >= 0 ); // An item is selected mRemoveButton->setEnabled( value ); mEditButton->setEnabled( value ); mStandardButton->setEnabled( value ); } #include "emaileditwidget.moc" diff --git a/akonadi/contact/editor/emaileditwidget.h b/akonadi/contact/editor/emaileditwidget.h index 820464aa1..339349857 100644 --- a/akonadi/contact/editor/emaileditwidget.h +++ b/akonadi/contact/editor/emaileditwidget.h @@ -1,92 +1,92 @@ /* - This file is part of KContactManager. + This file is part of KAddressBook. Copyright (c) 2009 Tobias Koenig 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef EMAILEDITWIDGET_H #define EMAILEDITWIDGET_H #include namespace KABC { class Addressee; } class KLineEdit; class KListWidget; class QToolButton; /** * @short A widget for editing email addresses. * * The widget will show the preferred email address in a lineedit * and provides a button to open a dialog for further editing. */ class EmailEditWidget : public QWidget { Q_OBJECT public: explicit EmailEditWidget( QWidget *parent = 0 ); ~EmailEditWidget(); void loadContact( const KABC::Addressee &contact ); void storeContact( KABC::Addressee &contact ) const; void setReadOnly( bool readOnly ); private Q_SLOTS: void edit(); void textChanged( const QString& ); private: KLineEdit *mEmailEdit; QToolButton *mEditButton; QStringList mEmailList; }; class EmailEditDialog : public KDialog { Q_OBJECT public: EmailEditDialog( const QStringList &list, QWidget *parent = 0 ); ~EmailEditDialog(); QStringList emails() const; bool changed() const; protected Q_SLOTS: void add(); void edit(); void remove(); void standard(); void selectionChanged(); private: KListWidget *mEmailListBox; QPushButton *mAddButton; QPushButton *mRemoveButton; QPushButton *mEditButton; QPushButton *mStandardButton; bool mChanged; }; #endif diff --git a/akonadi/contact/editor/freebusyeditwidget.cpp b/akonadi/contact/editor/freebusyeditwidget.cpp index 083562cb9..bdf97a7ff 100644 --- a/akonadi/contact/editor/freebusyeditwidget.cpp +++ b/akonadi/contact/editor/freebusyeditwidget.cpp @@ -1,65 +1,65 @@ /* - This file is part of KContactManager. + This file is part of KAddressBook. Copyright (c) 2009 Tobias Koenig 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "freebusyeditwidget.h" #include #include #include #include FreeBusyEditWidget::FreeBusyEditWidget( QWidget *parent ) : QWidget( parent ) { QHBoxLayout *layout = new QHBoxLayout( this ); layout->setMargin( 0 ); mURL = new KUrlRequester; layout->addWidget( mURL ); } FreeBusyEditWidget::~FreeBusyEditWidget() { } void FreeBusyEditWidget::loadContact( const KABC::Addressee &contact ) { if ( contact.preferredEmail().isEmpty() ) return; mURL->setUrl( KCal::FreeBusyUrlStore::self()->readUrl( contact.preferredEmail() ) ); } void FreeBusyEditWidget::storeContact( KABC::Addressee &contact ) const { if ( contact.preferredEmail().isEmpty() ) return; KCal::FreeBusyUrlStore::self()->writeUrl( contact.preferredEmail(), mURL->url().url() ); KCal::FreeBusyUrlStore::self()->sync(); } void FreeBusyEditWidget::setReadOnly( bool readOnly ) { mURL->setEnabled( !readOnly ); } #include "freebusyeditwidget.moc" diff --git a/akonadi/contact/editor/freebusyeditwidget.h b/akonadi/contact/editor/freebusyeditwidget.h index d43635b77..cbf25bb23 100644 --- a/akonadi/contact/editor/freebusyeditwidget.h +++ b/akonadi/contact/editor/freebusyeditwidget.h @@ -1,51 +1,51 @@ /* - This file is part of KContactManager. + This file is part of KAddressBook. Copyright (c) 2009 Tobias Koenig 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef FREEBUSYEDITWIDGET_H #define FREEBUSYEDITWIDGET_H #include namespace KABC { class Addressee; } class KUrlRequester; class FreeBusyEditWidget : public QWidget { Q_OBJECT public: FreeBusyEditWidget( QWidget *parent = 0 ); ~FreeBusyEditWidget(); void loadContact( const KABC::Addressee &contact ); void storeContact( KABC::Addressee &contact ) const; void setReadOnly( bool readOnly ); private: KUrlRequester *mURL; bool mReadOnly; }; #endif diff --git a/akonadi/contact/editor/imagewidget.cpp b/akonadi/contact/editor/imagewidget.cpp index b14da40cc..a1b57ea76 100644 --- a/akonadi/contact/editor/imagewidget.cpp +++ b/akonadi/contact/editor/imagewidget.cpp @@ -1,280 +1,280 @@ /* - This file is part of KContactManager. + This file is part of KAddressBook. Copyright (c) 2009 Tobias Koenig 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "imagewidget.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include /** * @short Small helper class to load image from network */ class ImageLoader { public: ImageLoader( QWidget *parent = 0 ); QImage loadImage( const KUrl &url, bool *ok ); private: QImage mImage; QWidget *mParent; }; ImageLoader::ImageLoader( QWidget *parent ) : mParent( parent ) { } QImage ImageLoader::loadImage( const KUrl &url, bool *ok ) { QImage image; QString tempFile; if ( url.isEmpty() ) return image; (*ok) = false; if ( url.isLocalFile() ) { if ( image.load( url.toLocalFile() ) ) { (*ok) = true; } } else if ( KIO::NetAccess::download( url, tempFile, mParent ) ) { if ( image.load( tempFile ) ) { (*ok) = true; } KIO::NetAccess::removeTempFile( tempFile ); } if ( !(*ok) ) { // image does not exist (any more) KMessageBox::sorry( mParent, i18n( "This contact's image cannot be found." ) ); return image; } QPixmap pixmap = QPixmap::fromImage( image ); image = KPixmapRegionSelectorDialog::getSelectedImage( pixmap, 100, 140, mParent ); if ( image.isNull() ) { (*ok) = false; return image; } if ( image.height() != 140 || image.width() != 100 ) { if ( image.height() > image.width() ) image = image.scaledToHeight( 140 ); else image = image.scaledToWidth( 100 ); } (*ok) = true; return image; } ImageWidget::ImageWidget( Type type, QWidget *parent ) : QPushButton( parent ), mType( type ), mHasImage( false ), mReadOnly( false ), mImageLoader( 0 ) { setAcceptDrops( true ); setIconSize( QSize( 100, 130 ) ); setFixedSize( QSize( 120, 160 ) ); connect( this, SIGNAL( clicked() ), SLOT( changeImage() ) ); updateView(); } ImageWidget::~ImageWidget() { delete mImageLoader; } void ImageWidget::loadContact( const KABC::Addressee &contact ) { const KABC::Picture picture = (mType == Photo ? contact.photo() : contact.logo()); if ( picture.isIntern() && !picture.data().isNull() ) { mHasImage = true; mImage = picture.data(); } updateView(); } void ImageWidget::storeContact( KABC::Addressee &contact ) const { if ( mType == Photo ) contact.setPhoto( mImage ); else contact.setLogo( mImage ); } void ImageWidget::setReadOnly( bool readOnly ) { mReadOnly = readOnly; } void ImageWidget::updateView() { if ( mHasImage ) { setIcon( QPixmap::fromImage( mImage ) ); } else { setIcon( KIcon( "user-identity" ) ); } } void ImageWidget::dragEnterEvent( QDragEnterEvent *event ) { const QMimeData *mimeData = event->mimeData(); event->setAccepted( mimeData->hasImage() || mimeData->hasUrls() ); } void ImageWidget::dropEvent( QDropEvent *event ) { if ( mReadOnly ) return; const QMimeData *mimeData = event->mimeData(); if ( mimeData->hasImage() ) { mImage = qvariant_cast(mimeData->imageData()); mHasImage = true; updateView(); } const KUrl::List urls = KUrl::List::fromMimeData( mimeData ); if ( urls.isEmpty() ) { // oops, no data event->setAccepted( false ); } else { bool ok = false; const QImage image = imageLoader()->loadImage( urls.first(), &ok ); if ( ok ) { mImage = image; mHasImage = true; updateView(); } } } void ImageWidget::mousePressEvent( QMouseEvent *event ) { mDragStartPos = event->pos(); QPushButton::mousePressEvent( event ); } void ImageWidget::mouseMoveEvent( QMouseEvent *event ) { if ( (event->buttons() & Qt::LeftButton) && (event->pos() - mDragStartPos).manhattanLength() > KGlobalSettings::dndEventDelay() ) { if ( mHasImage ) { QDrag *drag = new QDrag( this ); drag->setMimeData( new QMimeData() ); drag->mimeData()->setImageData( mImage ); drag->start(); } } } void ImageWidget::contextMenuEvent( QContextMenuEvent *event ) { QMenu menu; if ( mType == Photo ) { if ( !mReadOnly ) menu.addAction( i18n( "Change photo..." ), this, SLOT( changeImage() ) ); if ( mHasImage ) { menu.addAction( i18n( "Save photo..." ), this, SLOT( saveImage() ) ); if ( !mReadOnly ) menu.addAction( i18n( "Remove photo" ), this, SLOT( deleteImage() ) ); } } else { if ( !mReadOnly ) menu.addAction( i18n( "Change logo..." ), this, SLOT( changeImage() ) ); if ( mHasImage ) { menu.addAction( i18n( "Save logo..." ), this, SLOT( saveImage() ) ); if ( !mReadOnly ) menu.addAction( i18n( "Remove logo" ), this, SLOT( deleteImage() ) ); } } menu.exec( event->globalPos() ); } void ImageWidget::changeImage() { const KUrl url = KFileDialog::getOpenUrl( QString(), KImageIO::pattern(), this ); if ( url.isValid() ) { bool ok = false; const QImage image = imageLoader()->loadImage( url, &ok ); if ( ok ) { mImage = image; mHasImage = true; updateView(); } } } void ImageWidget::saveImage() { const QString fileName = KFileDialog::getSaveFileName( KUrl(), KImageIO::pattern(), this ); if ( !fileName.isEmpty() ) mImage.save( fileName ); } void ImageWidget::deleteImage() { mHasImage = false; mImage = QImage(); updateView(); } ImageLoader* ImageWidget::imageLoader() { if ( !mImageLoader ) mImageLoader = new ImageLoader; return mImageLoader; } diff --git a/akonadi/contact/editor/imagewidget.h b/akonadi/contact/editor/imagewidget.h index 92c1419fa..f9ff669e5 100644 --- a/akonadi/contact/editor/imagewidget.h +++ b/akonadi/contact/editor/imagewidget.h @@ -1,83 +1,83 @@ /* - This file is part of KContactManager. + This file is part of KAddressBook. Copyright (c) 2009 Tobias Koenig 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef IMAGEWIDGET_H #define IMAGEWIDGET_H #include #include namespace KABC { class Addressee; } class ImageLoader; class ImageWidget : public QPushButton { Q_OBJECT public: enum Type { Photo, Logo }; ImageWidget( Type type, QWidget *parent = 0 ); ~ImageWidget(); void loadContact( const KABC::Addressee &contact ); void storeContact( KABC::Addressee &contact ) const; void setReadOnly( bool readOnly ); protected: // image drop handling virtual void dragEnterEvent( QDragEnterEvent* ); virtual void dropEvent( QDropEvent* ); // image drag handling virtual void mousePressEvent( QMouseEvent* ); virtual void mouseMoveEvent( QMouseEvent* ); // context menu handling virtual void contextMenuEvent( QContextMenuEvent* ); private Q_SLOTS: void updateView(); void changeImage(); void saveImage(); void deleteImage(); private: ImageLoader *imageLoader(); Type mType; QImage mImage; bool mHasImage; bool mReadOnly; QPoint mDragStartPos; ImageLoader *mImageLoader; }; #endif diff --git a/akonadi/contact/editor/imeditwidget.cpp b/akonadi/contact/editor/imeditwidget.cpp index b4c97400c..91e035cf7 100644 --- a/akonadi/contact/editor/imeditwidget.cpp +++ b/akonadi/contact/editor/imeditwidget.cpp @@ -1,60 +1,60 @@ /* - This file is part of KContactManager. + This file is part of KAddressBook. Copyright (c) 2009 Tobias Koenig 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "imeditwidget.h" #include #include #include IMEditWidget::IMEditWidget( QWidget *parent ) : QWidget( parent ) { QHBoxLayout *layout = new QHBoxLayout( this ); layout->setMargin( 0 ); mIMEdit = new KLineEdit; layout->addWidget( mIMEdit ); } IMEditWidget::~IMEditWidget() { } void IMEditWidget::loadContact( const KABC::Addressee &contact ) { mIMEdit->setText( contact.custom( "KADDRESSBOOK", "X-IMAddress" ) ); } void IMEditWidget::storeContact( KABC::Addressee &contact ) const { if ( !mIMEdit->text().isEmpty() ) contact.insertCustom( "KADDRESSBOOK", "X-IMAddress", mIMEdit->text() ); else contact.removeCustom( "KADDRESSBOOK", "X-IMAddress" ); } void IMEditWidget::setReadOnly( bool readOnly ) { mIMEdit->setReadOnly( readOnly ); } #include "imeditwidget.moc" diff --git a/akonadi/contact/editor/imeditwidget.h b/akonadi/contact/editor/imeditwidget.h index a82e92f65..c1a7ed75d 100644 --- a/akonadi/contact/editor/imeditwidget.h +++ b/akonadi/contact/editor/imeditwidget.h @@ -1,54 +1,54 @@ /* - This file is part of KContactManager. + This file is part of KAddressBook. Copyright (c) 2009 Tobias Koenig 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef IMEDITWIDGET_H #define IMEDITWIDGET_H #include namespace KABC { class Addressee; } class KLineEdit; /** * This widget displays an input field for changing * the instant messaging id of a contact. */ class IMEditWidget : public QWidget { Q_OBJECT public: IMEditWidget( QWidget *parent = 0 ); ~IMEditWidget(); void loadContact( const KABC::Addressee &contact ); void storeContact( KABC::Addressee &contact ) const; void setReadOnly( bool readOnly ); private: KLineEdit *mIMEdit; }; #endif diff --git a/akonadi/contact/editor/nameeditwidget.cpp b/akonadi/contact/editor/nameeditwidget.cpp index d008e54ee..abb40f8ce 100644 --- a/akonadi/contact/editor/nameeditwidget.cpp +++ b/akonadi/contact/editor/nameeditwidget.cpp @@ -1,70 +1,70 @@ /* - This file is part of KContactManager. + This file is part of KAddressBook. Copyright (c) 2009 Tobias Koenig 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "nameeditwidget.h" #include #include #include #include #include NameEditWidget::NameEditWidget( QWidget *parent ) : QWidget( parent ) { QHBoxLayout *layout = new QHBoxLayout( this ); layout->setMargin( 0 ); layout->setSpacing( KDialog::spacingHint() ); mNameEdit = new KLineEdit; layout->addWidget( mNameEdit ); connect( mNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( textChanged( const QString& ) ) ); } NameEditWidget::~NameEditWidget() { } void NameEditWidget::setReadOnly( bool readOnly ) { mNameEdit->setReadOnly( readOnly ); } void NameEditWidget::loadContact( const KABC::Addressee &contact ) { mNameEdit->setText( contact.assembledName() ); } void NameEditWidget::storeContact( KABC::Addressee &contact ) const { contact.setNameFromString( mNameEdit->text() ); } void NameEditWidget::textChanged( const QString &text ) { KABC::Addressee contact; contact.setNameFromString( text ); emit nameChanged( contact ); } #include "nameeditwidget.moc" diff --git a/akonadi/contact/editor/nameeditwidget.h b/akonadi/contact/editor/nameeditwidget.h index 1bcce72cc..ff327959c 100644 --- a/akonadi/contact/editor/nameeditwidget.h +++ b/akonadi/contact/editor/nameeditwidget.h @@ -1,66 +1,66 @@ /* - This file is part of KContactManager. + This file is part of KAddressBook. Copyright (c) 2009 Tobias Koenig 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef NAMEEDITWIDGET_H #define NAMEEDITWIDGET_H #include #include class KLineEdit; /** * @short A widget for editing the name of a contact. * * The widget will show the name in a lineedit * and provides a button to open a dialog for editing of * the single name components. */ class NameEditWidget : public QWidget { Q_OBJECT public: explicit NameEditWidget( QWidget *parent = 0 ); ~NameEditWidget(); void loadContact( const KABC::Addressee &contact ); void storeContact( KABC::Addressee &contact ) const; void setReadOnly( bool readOnly ); Q_SIGNALS: /** * This signal is emitted whenever the name has been changed. * * @param contact A dummy contact that contains only the name components. */ void nameChanged( const KABC::Addressee &contact ); private Q_SLOTS: void textChanged( const QString& ); private: KLineEdit *mNameEdit; KABC::Addressee mContact; }; #endif diff --git a/akonadi/contact/editor/phoneeditwidget.cpp b/akonadi/contact/editor/phoneeditwidget.cpp index 3c42c1c58..0556b41ca 100644 --- a/akonadi/contact/editor/phoneeditwidget.cpp +++ b/akonadi/contact/editor/phoneeditwidget.cpp @@ -1,395 +1,395 @@ /* - This file is part of KContactManager. + This file is part of KAddressBook. Copyright (c) 2009 Tobias Koenig 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 "phoneeditwidget.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include PhoneTypeCombo::PhoneTypeCombo( QWidget *parent ) : KComboBox( parent ), mType( KABC::PhoneNumber::Home ), mLastSelected( 0 ) { for ( int i = 0; i < KABC::PhoneNumber::typeList().count(); ++i ) mTypeList.append( KABC::PhoneNumber::typeList().at( i ) ); mTypeList.append( -1 ); // Others... update(); connect( this, SIGNAL( activated( int ) ), this, SLOT( selected( int ) ) ); } PhoneTypeCombo::~PhoneTypeCombo() { } void PhoneTypeCombo::setType( KABC::PhoneNumber::Type type ) { if ( !mTypeList.contains( type ) ) mTypeList.insert( mTypeList.at( mTypeList.count() - 1 ), type ); mType = type; update(); } KABC::PhoneNumber::Type PhoneTypeCombo::type() const { return mType; } void PhoneTypeCombo::update() { clear(); for ( int i = 0; i < mTypeList.count(); ++i ) { if ( mTypeList.at( i ) == -1 ) // "Other..." entry addItem( i18nc( "@item:inlistbox Category of contact info field", "Other..." ) ); else addItem( KABC::PhoneNumber::typeLabel( KABC::PhoneNumber::Type( mTypeList.at( i ) ) ) ); } setCurrentIndex( mLastSelected = mTypeList.indexOf( mType ) ); } void PhoneTypeCombo::selected( int pos ) { if ( mTypeList.at( pos ) == -1 ) otherSelected(); else { mType = KABC::PhoneNumber::Type( mTypeList.at( pos ) ); mLastSelected = pos; } } void PhoneTypeCombo::otherSelected() { PhoneTypeDialog dlg( mType, this ); if ( dlg.exec() ) { mType = dlg.type(); if ( !mTypeList.contains( mType ) ) mTypeList.insert( mTypeList.at( mTypeList.count() - 1 ), mType ); } else { setType( KABC::PhoneNumber::Type( mTypeList.at( mLastSelected ) ) ); } update(); } PhoneNumberWidget::PhoneNumberWidget( QWidget *parent ) : QWidget( parent ) { QHBoxLayout *layout = new QHBoxLayout( this ); layout->setSpacing( 11 ); layout->setMargin( 0 ); mTypeCombo = new PhoneTypeCombo( this ); mNumberEdit = new KLineEdit( this ); layout->addWidget( mTypeCombo ); layout->addWidget( mNumberEdit ); connect( mNumberEdit, SIGNAL( textChanged( const QString& ) ), SIGNAL( modified() ) ); } void PhoneNumberWidget::setNumber( const KABC::PhoneNumber &number ) { mNumber = number; mTypeCombo->setType( number.type() ); mNumberEdit->setText( number.number() ); } KABC::PhoneNumber PhoneNumberWidget::number() const { KABC::PhoneNumber number( mNumber ); number.setType( mTypeCombo->type() ); number.setNumber( mNumberEdit->text() ); return number; } void PhoneNumberWidget::setReadOnly( bool readOnly ) { mTypeCombo->setEnabled( !readOnly ); mNumberEdit->setReadOnly( readOnly ); } PhoneNumberListWidget::PhoneNumberListWidget( QWidget *parent ) : QWidget( parent ), mReadOnly( false ) { mWidgetLayout = new QVBoxLayout( this ); mMapper = new QSignalMapper( this ); connect( mMapper, SIGNAL( mapped( int ) ), SLOT( changed( int ) ) ); setPhoneNumbers( KABC::PhoneNumber::List() ); } PhoneNumberListWidget::~PhoneNumberListWidget() { } void PhoneNumberListWidget::setReadOnly( bool readOnly ) { mReadOnly = readOnly; foreach ( PhoneNumberWidget *const widget, mWidgets ) widget->setReadOnly( readOnly ); } int PhoneNumberListWidget::phoneNumberCount() const { return mPhoneNumberList.count(); } void PhoneNumberListWidget::setPhoneNumbers( const KABC::PhoneNumber::List &list ) { mPhoneNumberList = list; KABC::PhoneNumber::TypeList types; types << KABC::PhoneNumber::Home; types << KABC::PhoneNumber::Work; types << KABC::PhoneNumber::Cell; // add an empty entry per default if ( mPhoneNumberList.count() < 3 ) for ( int i = mPhoneNumberList.count(); i < 3; ++i ) mPhoneNumberList.append( KABC::PhoneNumber( QString(), types[ i ] ) ); recreateNumberWidgets(); } KABC::PhoneNumber::List PhoneNumberListWidget::phoneNumbers() const { KABC::PhoneNumber::List list; KABC::PhoneNumber::List::ConstIterator it; for ( it = mPhoneNumberList.constBegin(); it != mPhoneNumberList.constEnd(); ++it ) if ( !(*it).number().isEmpty() ) list.append( *it ); return list; } void PhoneNumberListWidget::add() { mPhoneNumberList.append( KABC::PhoneNumber() ); recreateNumberWidgets(); } void PhoneNumberListWidget::remove() { mPhoneNumberList.removeLast(); recreateNumberWidgets(); } void PhoneNumberListWidget::recreateNumberWidgets() { foreach ( QWidget *const widget, mWidgets ) { mWidgetLayout->removeWidget( widget ); delete widget; } mWidgets.clear(); KABC::PhoneNumber::List::ConstIterator it; int counter = 0; for ( it = mPhoneNumberList.constBegin(); it != mPhoneNumberList.constEnd(); ++it ) { PhoneNumberWidget *wdg = new PhoneNumberWidget( this ); wdg->setNumber( *it ); mMapper->setMapping( wdg, counter ); connect( wdg, SIGNAL( modified() ), mMapper, SLOT( map() ) ); mWidgetLayout->addWidget( wdg ); mWidgets.append( wdg ); wdg->show(); ++counter; } setReadOnly( mReadOnly ); } void PhoneNumberListWidget::changed( int pos ) { mPhoneNumberList[ pos ] = mWidgets.at( pos )->number(); } PhoneEditWidget::PhoneEditWidget( QWidget *parent ) : QWidget( parent ), mReadOnly( false ) { QGridLayout *layout = new QGridLayout( this ); layout->setSpacing( KDialog::spacingHint() ); mListScrollArea = new QScrollArea( this ); mPhoneNumberListWidget = new PhoneNumberListWidget; mListScrollArea->setWidget( mPhoneNumberListWidget ); mListScrollArea->setWidgetResizable( true ); // ugly but size policies seem to be messed up dialog (parent) wide const int scrollAreaMinHeight = mPhoneNumberListWidget->sizeHint().height() + mListScrollArea->horizontalScrollBar()->sizeHint().height(); mListScrollArea->setMinimumHeight( scrollAreaMinHeight ); layout->addWidget( mListScrollArea, 0, 0, 1, 2 ); mAddButton = new QPushButton( i18n( "Add" ), this ); mAddButton->setMaximumSize( mAddButton->sizeHint() ); layout->addWidget( mAddButton, 1, 0, Qt::AlignRight ); mRemoveButton = new QPushButton( i18n( "Remove" ), this ); mRemoveButton->setMaximumSize( mRemoveButton->sizeHint() ); layout->addWidget( mRemoveButton, 1, 1 ); connect( mAddButton, SIGNAL( clicked() ), mPhoneNumberListWidget, SLOT( add() ) ); connect( mRemoveButton, SIGNAL( clicked() ), mPhoneNumberListWidget, SLOT( remove() ) ); connect( mAddButton, SIGNAL( clicked() ), SLOT( changed() ) ); connect( mRemoveButton, SIGNAL( clicked() ), SLOT( changed() ) ); } PhoneEditWidget::~PhoneEditWidget() { } void PhoneEditWidget::setReadOnly( bool readOnly ) { mReadOnly = readOnly; mAddButton->setEnabled( !readOnly ); mRemoveButton->setEnabled( !readOnly && mPhoneNumberListWidget->phoneNumberCount() > 3 ); mPhoneNumberListWidget->setReadOnly( readOnly ); } void PhoneEditWidget::changed() { mRemoveButton->setEnabled( !mReadOnly && mPhoneNumberListWidget->phoneNumberCount() > 3 ); } void PhoneEditWidget::loadContact( const KABC::Addressee &contact ) { mPhoneNumberListWidget->setPhoneNumbers( contact.phoneNumbers() ); changed(); } void PhoneEditWidget::storeContact( KABC::Addressee &contact ) const { const KABC::PhoneNumber::List oldNumbers = contact.phoneNumbers(); for ( int i = 0; i < oldNumbers.count(); ++i ) contact.removePhoneNumber( oldNumbers.at( i ) ); const KABC::PhoneNumber::List newNumbers = mPhoneNumberListWidget->phoneNumbers(); for ( int i = 0; i < newNumbers.count(); ++i ) contact.insertPhoneNumber( newNumbers.at( i ) ); } /////////////////////////////////////////// // PhoneTypeDialog PhoneTypeDialog::PhoneTypeDialog( KABC::PhoneNumber::Type type, QWidget *parent ) : KDialog( parent), mType( type ) { setCaption( i18n( "Edit Phone Number" ) ); setButtons( Ok | Cancel ); setDefaultButton( Ok ); showButtonSeparator( true ); QWidget *page = new QWidget( this ); setMainWidget( page ); QVBoxLayout *layout = new QVBoxLayout( page ); layout->setSpacing( spacingHint() ); layout->setMargin( 0 ); mPreferredBox = new QCheckBox( i18n( "This is the preferred phone number" ), page ); layout->addWidget( mPreferredBox ); QGroupBox *box = new QGroupBox( i18n( "Types" ), page ); layout->addWidget( box ); QGridLayout *buttonLayout = new QGridLayout( box ); // fill widgets mTypeList = KABC::PhoneNumber::typeList(); mTypeList.removeAll( KABC::PhoneNumber::Pref ); KABC::PhoneNumber::TypeList::ConstIterator it; mGroup = new QButtonGroup( box ); mGroup->setExclusive( false ); int row, column, counter; row = column = counter = 0; for ( it = mTypeList.constBegin(); it != mTypeList.constEnd(); ++it, ++counter ) { QCheckBox *cb = new QCheckBox( KABC::PhoneNumber::typeLabel( *it ), box ); cb->setChecked( type & mTypeList[ counter ] ); buttonLayout->addWidget( cb, row, column ); mGroup->addButton( cb ); column++; if ( column == 5 ) { column = 0; ++row; } } mPreferredBox->setChecked( mType & KABC::PhoneNumber::Pref ); } KABC::PhoneNumber::Type PhoneTypeDialog::type() const { KABC::PhoneNumber::Type type = 0; for ( int i = 0; i < mGroup->buttons().count(); ++i ) { QCheckBox *box = dynamic_cast( mGroup->buttons().at( i ) ) ; if ( box && box->isChecked() ) type |= mTypeList[ i ]; } if ( mPreferredBox->isChecked() ) type = type | KABC::PhoneNumber::Pref; else type = type & ~KABC::PhoneNumber::Pref; return type; } #include "phoneeditwidget.moc" diff --git a/akonadi/contact/editor/phoneeditwidget.h b/akonadi/contact/editor/phoneeditwidget.h index ce8f18479..c1dd4176a 100644 --- a/akonadi/contact/editor/phoneeditwidget.h +++ b/akonadi/contact/editor/phoneeditwidget.h @@ -1,266 +1,266 @@ /* - This file is part of KContactManager. + This file is part of KAddressBook. Copyright (c) 2009 Tobias Koenig 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 PHONEEDITWIDGET_H #define PHONEEDITWIDGET_H #include #include #include #include class KLineEdit; class QButtonGroup; class QCheckBox; class QScrollArea; class QSignalMapper; class QVBoxLayout; /** * @short A combobox to select a phone number type. */ class PhoneTypeCombo : public KComboBox { Q_OBJECT public: /** * Creates a phone type combo. * * @param parent The parent widget. */ PhoneTypeCombo( QWidget *parent = 0 ); /** * Destroys the phone type combo. */ ~PhoneTypeCombo(); /** * Sets the phone number @p type that shall be selected. */ void setType( KABC::PhoneNumber::Type type ); /** * Returns the selected phone number type. */ KABC::PhoneNumber::Type type() const; private Q_SLOTS: void selected( int ); void otherSelected(); private: void update(); KABC::PhoneNumber::Type mType; int mLastSelected; QList mTypeList; }; /** * A widget that provides selectors for the type * and number of a phone number entry. */ class PhoneNumberWidget : public QWidget { Q_OBJECT public: /** * Creates a new phone number widget. * * @param parent The parent widget. */ PhoneNumberWidget( QWidget *parent = 0 ); /** * Sets the phone @p number of the widget. */ void setNumber( const KABC::PhoneNumber &number ); /** * Returns the phone number of the widget. */ KABC::PhoneNumber number() const; /** * Sets the widget to @p readOnly mode. */ void setReadOnly( bool readOnly ); Q_SIGNALS: void modified(); private: PhoneTypeCombo *mTypeCombo; KLineEdit *mNumberEdit; KABC::PhoneNumber mNumber; }; /** * A widgets that groups together a list of PhoneNumberWidgets */ class PhoneNumberListWidget : public QWidget { Q_OBJECT public: /** * Creates a new phone number list widget. * * @param parent The parent widget. */ PhoneNumberListWidget( QWidget *parent = 0 ); /** * Destroys the phone number list widget. */ ~PhoneNumberListWidget(); /** * Sets the @p list of phone numbers the widget shall show. */ void setPhoneNumbers( const KABC::PhoneNumber::List &list ); /** * Returns the list of phone numbers. */ KABC::PhoneNumber::List phoneNumbers() const; /** * Sets the widget to @p readOnly mode. */ void setReadOnly( bool readOnly ); /** * Returns the number of phone numbers available. */ int phoneNumberCount() const; public Q_SLOTS: /** * Adds a new phone number widget to this widget. */ void add(); /** * Removes the last phone number widget from this widget. */ void remove(); private Q_SLOTS: void changed( int ); private: void recreateNumberWidgets(); KABC::PhoneNumber::List mPhoneNumberList; QList mWidgets; QVBoxLayout *mWidgetLayout; bool mReadOnly; QSignalMapper *mMapper; }; /** * @short A widget for editing phone numbers of a contact. */ class PhoneEditWidget : public QWidget { Q_OBJECT public: /** * Creates a new phone edit widget. * * @param parent The parent widget. */ explicit PhoneEditWidget( QWidget *parent = 0 ); /** * Destroys the phone edit widget. */ ~PhoneEditWidget(); /** * Loads the data from @p contact to the widget. */ void loadContact( const KABC::Addressee &contact ); /** * Stores the data from the widget to the @p contact. */ void storeContact( KABC::Addressee &contact ) const; /** * Sets the widget to @p readOnly mode. */ void setReadOnly( bool readOnly ); private Q_SLOTS: void changed(); private: QPushButton *mAddButton; QPushButton *mRemoveButton; bool mReadOnly; QScrollArea *mListScrollArea; PhoneNumberListWidget *mPhoneNumberListWidget; }; /** * A dialog for editing phone number types. */ class PhoneTypeDialog : public KDialog { public: /** * Creates a new phone type dialog. * * @param type The initial type of the phone number. * @param parent The parent widget. */ PhoneTypeDialog( KABC::PhoneNumber::Type type, QWidget *parent = 0 ); /** * Returns the selected type. */ KABC::PhoneNumber::Type type() const; private: KABC::PhoneNumber::Type mType; KABC::PhoneNumber::TypeList mTypeList; QButtonGroup *mGroup; QCheckBox *mPreferredBox; }; #endif diff --git a/akonadi/contact/editor/secrecyeditwidget.cpp b/akonadi/contact/editor/secrecyeditwidget.cpp index f90a1554f..a4a84ee7c 100644 --- a/akonadi/contact/editor/secrecyeditwidget.cpp +++ b/akonadi/contact/editor/secrecyeditwidget.cpp @@ -1,69 +1,69 @@ /* - This file is part of KContactManager. + This file is part of KAddressBook. Copyright (c) 2009 Tobias Koenig 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "secrecyeditwidget.h" #include #include #include #include SecrecyEditWidget::SecrecyEditWidget( QWidget *parent ) : QWidget( parent ) { QVBoxLayout *layout = new QVBoxLayout( this ); layout->setMargin( 0 ); mSecrecyCombo = new KComboBox( this ); layout->addWidget( mSecrecyCombo ); const KABC::Secrecy::TypeList list = KABC::Secrecy::typeList(); KABC::Secrecy::TypeList::ConstIterator it; // (*it) is the type enum, which is also used as the index in the combo for ( it = list.begin(); it != list.end(); ++it ) mSecrecyCombo->insertItem( *it, KABC::Secrecy::typeLabel( *it ) ); } SecrecyEditWidget::~SecrecyEditWidget() { } void SecrecyEditWidget::setReadOnly( bool readOnly ) { mSecrecyCombo->setEnabled( !readOnly ); } void SecrecyEditWidget::loadContact( const KABC::Addressee &contact ) { if ( contact.secrecy().type() != KABC::Secrecy::Invalid ) mSecrecyCombo->setCurrentIndex( contact.secrecy().type() ); } void SecrecyEditWidget::storeContact( KABC::Addressee &contact ) const { KABC::Secrecy secrecy; secrecy.setType( (KABC::Secrecy::Type)mSecrecyCombo->currentIndex() ); contact.setSecrecy( secrecy ); } #include "secrecyeditwidget.moc" diff --git a/akonadi/contact/editor/secrecyeditwidget.h b/akonadi/contact/editor/secrecyeditwidget.h index 78d1eef9f..200660d89 100644 --- a/akonadi/contact/editor/secrecyeditwidget.h +++ b/akonadi/contact/editor/secrecyeditwidget.h @@ -1,50 +1,50 @@ /* - This file is part of KContactManager. + This file is part of KAddressBook. Copyright (c) 2009 Tobias Koenig 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef SECRECYEDITWIDGET_H #define SECRECYEDITWIDGET_H #include namespace KABC { class Addressee; } class KComboBox; class SecrecyEditWidget : public QWidget { Q_OBJECT public: explicit SecrecyEditWidget( QWidget *parent = 0 ); ~SecrecyEditWidget(); void loadContact( const KABC::Addressee &contact ); void storeContact( KABC::Addressee &contact ) const; void setReadOnly( bool readOnly ); private: KComboBox *mSecrecyCombo; }; #endif diff --git a/akonadi/contact/editor/soundeditwidget.cpp b/akonadi/contact/editor/soundeditwidget.cpp index 4d07c8032..6971b25a2 100644 --- a/akonadi/contact/editor/soundeditwidget.cpp +++ b/akonadi/contact/editor/soundeditwidget.cpp @@ -1,219 +1,219 @@ /* - This file is part of KContactManager. + This file is part of KAddressBook. Copyright (c) 2009 Tobias Koenig 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "soundeditwidget.h" #include #include #include #include #include #include #include #include #include #include /** * @short Small helper class to load sound from network */ class SoundLoader { public: SoundLoader( QWidget *parent = 0 ); QByteArray loadSound( const KUrl &url, bool *ok ); private: QByteArray mSound; QWidget *mParent; }; SoundLoader::SoundLoader( QWidget *parent ) : mParent( parent ) { } QByteArray SoundLoader::loadSound( const KUrl &url, bool *ok ) { QByteArray sound; QString tempFile; if ( url.isEmpty() ) return sound; (*ok) = false; if ( url.isLocalFile() ) { QFile file( url.toLocalFile() ); if ( file.open( QIODevice::ReadOnly ) ) { sound = file.readAll(); file.close(); (*ok) = true; } } else if ( KIO::NetAccess::download( url, tempFile, mParent ) ) { QFile file( tempFile ); if ( file.open( QIODevice::ReadOnly ) ) { sound = file.readAll(); file.close(); (*ok) = true; } KIO::NetAccess::removeTempFile( tempFile ); } if ( !(*ok) ) { KMessageBox::sorry( mParent, i18n( "This contact's sound cannot be found." ) ); return sound; } (*ok) = true; return sound; } SoundEditWidget::SoundEditWidget( QWidget *parent ) : QToolButton( parent ), mHasSound( false ), mReadOnly( false ), mSoundLoader( 0 ) { connect( this, SIGNAL( clicked() ), SLOT( playSound() ) ); updateView(); } SoundEditWidget::~SoundEditWidget() { delete mSoundLoader; } void SoundEditWidget::loadContact( const KABC::Addressee &contact ) { const KABC::Sound sound = contact.sound(); if ( sound.isIntern() && !sound.data().isEmpty() ) { mHasSound = true; mSound = sound.data(); } updateView(); } void SoundEditWidget::storeContact( KABC::Addressee &contact ) const { KABC::Sound sound( contact.sound() ); sound.setData( mSound ); contact.setSound( sound ); } void SoundEditWidget::setReadOnly( bool readOnly ) { mReadOnly = readOnly; } void SoundEditWidget::updateView() { if ( mHasSound ) { setIcon( KIcon( "audio-volume-medium" ) ); setToolTip( i18n( "Click to play pronunciation" ) ); } else { setIcon( KIcon( "audio-volume-muted" ) ); setToolTip( i18n( "No pronunciation available" ) ); } } void SoundEditWidget::contextMenuEvent( QContextMenuEvent *event ) { QMenu menu; if ( mHasSound ) menu.addAction( i18n( "Play" ), this, SLOT( playSound() ) ); if ( !mReadOnly ) menu.addAction( i18n( "Change..." ), this, SLOT( changeSound() ) ); if ( mHasSound ) { menu.addAction( i18n( "Save..." ), this, SLOT( saveSound() ) ); if ( !mReadOnly ) menu.addAction( i18n( "Remove" ), this, SLOT( deleteSound() ) ); } menu.exec( event->globalPos() ); } void SoundEditWidget::playSound() { if ( !mHasSound ) return; Phonon::MediaObject* player = Phonon::createPlayer( Phonon::NotificationCategory ); QBuffer* soundData = new QBuffer( player ); soundData->setData( mSound ); player->setCurrentSource( soundData ); player->setParent( this ); connect( player, SIGNAL( finished() ), player, SLOT( deleteLater() ) ); player->play(); } void SoundEditWidget::changeSound() { const KUrl url = KFileDialog::getOpenUrl( QString(), "*.wav", this ); if ( url.isValid() ) { bool ok = false; const QByteArray sound = soundLoader()->loadSound( url, &ok ); if ( ok ) { mSound = sound; mHasSound = true; updateView(); } } } void SoundEditWidget::saveSound() { const QString fileName = KFileDialog::getSaveFileName( KUrl(), "*.wav", this ); if ( !fileName.isEmpty() ) { QFile file( fileName ); if ( file.open( QIODevice::WriteOnly ) ) { file.write( mSound ); file.close(); } } } void SoundEditWidget::deleteSound() { mHasSound = false; mSound = QByteArray(); updateView(); } SoundLoader* SoundEditWidget::soundLoader() { if ( !mSoundLoader ) mSoundLoader = new SoundLoader; return mSoundLoader; } diff --git a/akonadi/contact/editor/soundeditwidget.h b/akonadi/contact/editor/soundeditwidget.h index f5e082db5..e9ea0b272 100644 --- a/akonadi/contact/editor/soundeditwidget.h +++ b/akonadi/contact/editor/soundeditwidget.h @@ -1,69 +1,69 @@ /* - This file is part of KContactManager. + This file is part of KAddressBook. Copyright (c) 2009 Tobias Koenig 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef SOUNDEDITWIDGET_H #define SOUNDEDITWIDGET_H #include #include namespace KABC { class Addressee; } class SoundLoader; class SoundEditWidget : public QToolButton { Q_OBJECT public: SoundEditWidget( QWidget *parent = 0 ); ~SoundEditWidget(); void loadContact( const KABC::Addressee &contact ); void storeContact( KABC::Addressee &contact ) const; void setReadOnly( bool readOnly ); protected: // context menu handling virtual void contextMenuEvent( QContextMenuEvent* ); private Q_SLOTS: void playSound(); void updateView(); void changeSound(); void saveSound(); void deleteSound(); private: SoundLoader *soundLoader(); QByteArray mSound; bool mHasSound; bool mReadOnly; SoundLoader *mSoundLoader; }; #endif