kaddressbook
distributionlistentryview.cpp
Go to the documentation of this file.00001 #include "distributionlistentryview.h"
00002 #include "imagewidget.h"
00003 #include <interfaces/core.h>
00004
00005 #include <kabc/addressbook.h>
00006 #include <kabc/resource.h>
00007 #include <kabc/resourceabc.h>
00008
00009 #include <kdialog.h>
00010 #include <kiconloader.h>
00011 #include <klocale.h>
00012 #include <kurllabel.h>
00013
00014 #include <QtCore/QStringList>
00015 #include <QtGui/QButtonGroup>
00016 #include <QtGui/QComboBox>
00017 #include <QtGui/QGridLayout>
00018 #include <QtGui/QHBoxLayout>
00019 #include <QtGui/QLabel>
00020 #include <QtGui/QPixmap>
00021 #include <QtGui/QRadioButton>
00022 #include <QtGui/QVBoxLayout>
00023
00024
00025 KAB::DistributionListEntryView::DistributionListEntryView( KAB::Core* core, QWidget* parent ) : QWidget( parent ), m_core( core ), m_emailGroup( 0 )
00026 {
00027 m_mainLayout = new QVBoxLayout( this );
00028 m_mainLayout->setSpacing( KDialog::spacingHint() );
00029 m_mainLayout->setMargin( KDialog::marginHint() );
00030
00031 QWidget* headerWidget = new QWidget;
00032 QBoxLayout* headerLayout = new QHBoxLayout( headerWidget );
00033 headerLayout->setSpacing( KDialog::spacingHint() * 3 );
00034
00035 m_imageLabel = new QLabel( this );
00036 headerLayout->addWidget( m_imageLabel, 0, Qt::AlignTop );
00037
00038 m_addresseeLabel = new QLabel( this );
00039 headerLayout->addWidget( m_addresseeLabel, 0, Qt::AlignTop );
00040 headerLayout->addStretch();
00041
00042 m_mainLayout->addWidget( headerWidget );
00043
00044 QWidget* distWidget = new QWidget;
00045 QBoxLayout* distLayout = new QHBoxLayout( distWidget );
00046 distLayout->setSpacing( KDialog::spacingHint() );
00047
00048 QLabel* distLabel = new QLabel( this );
00049 distLabel->setText( i18n( "<b>Distribution list:</b>" ) );
00050 distLabel->setWordWrap( false );
00051 distLayout->addWidget( distLabel );
00052
00053 m_distListLabel = new KUrlLabel( this );
00054 distLabel->setBuddy( m_distListLabel );
00055 connect( m_distListLabel, SIGNAL( leftClickedUrl( const QString& ) ),
00056 this, SIGNAL( distributionListClicked( const QString& ) ) );
00057 distLayout->addWidget( m_distListLabel );
00058 distLayout->addStretch();
00059 m_mainLayout->addWidget( distWidget );
00060
00061 QLabel* emailLabel = new QLabel( this );
00062 emailLabel->setText( i18n( "<b>Email address to use in this list:</b>" ) );
00063 emailLabel->setWordWrap( false );
00064 m_mainLayout->addWidget( emailLabel );
00065
00066 QWidget* emailWidget = new QWidget;
00067 QBoxLayout* emailLayout = new QHBoxLayout( emailWidget );
00068 emailLayout->setSpacing( KDialog::spacingHint() );
00069 emailLayout->addSpacing( 30 );
00070
00071 QWidget* radioWidget = new QWidget;
00072 m_radioLayout = new QGridLayout( radioWidget );
00073 emailLayout->addWidget( radioWidget );
00074 emailLayout->addStretch();
00075 m_mainLayout->addWidget( emailWidget );
00076
00077 QWidget* resourceWidget = new QWidget;
00078 QBoxLayout* resourceLayout = new QHBoxLayout( resourceWidget );
00079 resourceLayout->setSpacing( KDialog::spacingHint() );
00080 m_resourceLabel = new QLabel( this );
00081 resourceLayout->addWidget( m_resourceLabel );
00082 resourceLayout->addStretch();
00083
00084 m_mainLayout->addWidget( resourceWidget );
00085 m_mainLayout->addStretch();
00086 }
00087
00088 void KAB::DistributionListEntryView::emailButtonClicked( int id )
00089 {
00090 const QString email = m_idToEmail[ id ];
00091 if ( m_entry.email == email )
00092 return;
00093 m_list.removeEntry( m_entry.addressee, m_entry.email );
00094 m_entry.email = email;
00095 m_list.insertEntry( m_entry.addressee, m_entry.email );
00096 m_core->addressBook()->insertAddressee( m_list );
00097 }
00098
00099 void KAB::DistributionListEntryView::clear()
00100 {
00101 setEntry( KPIM::DistributionList(), KPIM::DistributionList::Entry() );
00102 }
00103
00104 void KAB::DistributionListEntryView::setEntry( const KPIM::DistributionList& list, const KPIM::DistributionList::Entry& entry )
00105 {
00106 m_list = list;
00107 m_entry = entry;
00108
00109 delete m_emailGroup;
00110 m_emailGroup = 0;
00111
00112 QPixmap pixmap;
00113 if ( m_entry.addressee.photo().data().isNull() )
00114 pixmap = KIcon( "user-identity" ).pixmap( 100, 140 );
00115 else
00116 pixmap = QPixmap::fromImage( m_entry.addressee.photo().data() );
00117 m_imageLabel->setPixmap( pixmap );
00118 m_addresseeLabel->setText( i18nc( "Formatted name, role, organization", "<qt><h2>%1</h2><p>%2<br/>%3</p></qt>", m_entry.addressee.formattedName(), m_entry.addressee.role(), m_entry.addressee.organization() ) );
00119 m_distListLabel->setUrl( m_list.name() );
00120 m_distListLabel->setText( m_list.name() );
00121 m_resourceLabel->setText( i18n( "<b>Address book:</b> %1", (m_entry.addressee.resource() ? m_entry.addressee.resource()->resourceName() : QString()) ) );
00122 m_resourceLabel->setWordWrap( false );
00123 m_emailGroup = new QWidget( this );
00124 QBoxLayout *emailGroupLayout = new QVBoxLayout( m_emailGroup );
00125 QButtonGroup* buttonGroup = new QButtonGroup( m_emailGroup );
00126 buttonGroup->setExclusive( true );
00127
00128 const QString preferred = m_entry.email.isNull() ? m_entry.addressee.preferredEmail() : m_entry.email;
00129 const QStringList mails = m_entry.addressee.emails();
00130 m_idToEmail.clear();
00131 int nextId = 0;
00132 foreach ( const QString it, mails )
00133 {
00134 QRadioButton* button = new QRadioButton( m_emailGroup );
00135 button->setText( it );
00136 buttonGroup->addButton( button, ++nextId );
00137 m_idToEmail.insert( nextId, it );
00138 if ( it == preferred )
00139 button->setChecked( true );
00140 button->setVisible( true );
00141 emailGroupLayout->addWidget( button );
00142 }
00143 connect( buttonGroup, SIGNAL( buttonClicked( int ) ),
00144 this, SLOT( emailButtonClicked( int ) ) );
00145 m_radioLayout->addWidget( m_emailGroup, 0, 0 );
00146 m_emailGroup->setVisible( true );
00147 m_mainLayout->invalidate();
00148 }
00149
00150
00151 #include "distributionlistentryview.moc"