kaddressbook

distributionlistentryview.cpp

00001 #include "distributionlistentryview.h"
00002 #include "imagewidget.h"
00003 #include <interfaces/core.h>
00004 
00005 #include <libkdepim/resourceabc.h>
00006 
00007 #include <kabc/addressbook.h>
00008 #include <kabc/resource.h>
00009 
00010 #include <kdialog.h>
00011 #include <kiconloader.h>
00012 #include <klocale.h>
00013 #include <kurllabel.h>
00014 
00015 #include <tqbuttongroup.h>
00016 #include <tqcombobox.h>
00017 #include <tqlabel.h>
00018 #include <tqlayout.h>
00019 #include <tqradiobutton.h>
00020 #include <tqstringlist.h>
00021 #include <tqvbuttongroup.h>
00022 
00023 KAB::DistributionListEntryView::DistributionListEntryView( KAB::Core* core, TQWidget* parent ) : TQWidget( parent ), m_core( core ), m_emailGroup( 0 )
00024 {
00025     m_mainLayout = new TQVBoxLayout( this );
00026     m_mainLayout->setSpacing( KDialog::spacingHint() );
00027     m_mainLayout->setMargin( KDialog::marginHint() );
00028 
00029     TQBoxLayout* headerLayout = new TQHBoxLayout;
00030     headerLayout->setSpacing( KDialog::spacingHint() * 3 );
00031 
00032     m_imageLabel = new TQLabel( this );
00033     m_imageLabel->setAutoResize( true );
00034     headerLayout->addWidget( m_imageLabel, 0, TQt::AlignTop );
00035 
00036     m_addresseeLabel = new TQLabel( this );
00037     headerLayout->addWidget( m_addresseeLabel, 0, TQt::AlignTop );
00038     headerLayout->addStretch();
00039 
00040     m_mainLayout->addItem( headerLayout );
00041 
00042     TQBoxLayout* distLayout = new TQHBoxLayout;
00043     distLayout->setSpacing( KDialog::spacingHint() );
00044 
00045     TQLabel* distLabel = new TQLabel( this );
00046     distLabel->setText( i18n( "<b>Distribution list:</b>" ) );
00047     distLabel->setAlignment( TQt::SingleLine );
00048     distLayout->addWidget( distLabel );
00049 
00050     m_distListLabel = new KURLLabel( this );
00051     distLabel->setBuddy( m_distListLabel );
00052     connect( m_distListLabel, TQT_SIGNAL( leftClickedURL( const TQString& ) ), 
00053              this, TQT_SIGNAL( distributionListClicked( const TQString& ) ) );
00054     distLayout->addWidget( m_distListLabel );
00055     distLayout->addStretch();
00056     m_mainLayout->addItem( distLayout );
00057 
00058     TQLabel* emailLabel = new TQLabel( this );
00059     emailLabel->setText( i18n( "<b>Email address to use in this list:</b>" ) );
00060     emailLabel->setAlignment( TQt::SingleLine );
00061     m_mainLayout->addWidget( emailLabel );
00062 
00063     TQBoxLayout* emailLayout = new TQHBoxLayout;
00064     emailLayout->setSpacing( KDialog::spacingHint() );
00065     emailLayout->addSpacing( 30 );
00066 
00067     m_radioLayout = new TQGridLayout;
00068     emailLayout->addItem( m_radioLayout );
00069     emailLayout->addStretch();
00070     m_mainLayout->addItem( emailLayout );
00071 
00072     TQBoxLayout* resourceLayout = new TQHBoxLayout;
00073     resourceLayout->setSpacing( KDialog::spacingHint() );
00074     m_resourceLabel = new TQLabel( this );
00075     resourceLayout->addWidget( m_resourceLabel );
00076     resourceLayout->addStretch();
00077 
00078     m_mainLayout->addItem( resourceLayout );
00079     m_mainLayout->addStretch();
00080 }
00081 
00082 void KAB::DistributionListEntryView::emailButtonClicked( int id )
00083 {
00084     const TQString email = m_idToEmail[ id ];
00085     if ( m_entry.email == email )
00086         return;
00087     m_list.removeEntry( m_entry.addressee, m_entry.email );
00088     m_entry.email = email;
00089     m_list.insertEntry( m_entry.addressee, m_entry.email );
00090     m_core->addressBook()->insertAddressee( m_list ); 
00091 }
00092 
00093 void KAB::DistributionListEntryView::clear()
00094 {
00095     setEntry( KPIM::DistributionList(), KPIM::DistributionList::Entry() );
00096 }
00097 
00098 void KAB::DistributionListEntryView::setEntry( const KPIM::DistributionList& list, const KPIM::DistributionList::Entry& entry )
00099 {    
00100     m_list = list;
00101     m_entry = entry;
00102 
00103     delete m_emailGroup;
00104     m_emailGroup = 0;
00105 
00106     TQPixmap pixmap;
00107     pixmap.convertFromImage( m_entry.addressee.photo().data() );
00108     m_imageLabel->setPixmap( pixmap.isNull() ? KGlobal::iconLoader()->loadIcon( "personal", KIcon::Desktop ) : pixmap );
00109     m_addresseeLabel->setText( i18n( "Formatted name, role, organization", "<qt><h2>%1</h2><p>%2<br/>%3</p></qt>" ).arg( m_entry.addressee.formattedName(), m_entry.addressee.role(), m_entry.addressee.organization() ) );
00110     m_distListLabel->setURL( m_list.name() );
00111     m_distListLabel->setText( m_list.name() );
00112     m_resourceLabel->setText( i18n( "<b>Address book:</b> %1" ).arg( m_entry.addressee.resource() ? m_entry.addressee.resource()->resourceName() : TQString() ) );
00113     m_resourceLabel->setAlignment( TQt::SingleLine );
00114  
00115     m_emailGroup = new TQVButtonGroup( this );
00116     m_emailGroup->setFlat( true );
00117     m_emailGroup->setExclusive( true );
00118     m_emailGroup->setFrameShape( TQFrame::NoFrame );
00119 
00120     const TQString preferred = m_entry.email.isNull() ? m_entry.addressee.preferredEmail() : m_entry.email;
00121     const TQStringList mails = m_entry.addressee.emails();
00122     m_idToEmail.clear();
00123     for ( TQStringList::ConstIterator it = mails.begin(); it != mails.end(); ++it )
00124     {
00125         TQRadioButton* button = new TQRadioButton( m_emailGroup );
00126         button->setText( *it );
00127         m_idToEmail.insert( m_emailGroup->insert( button ), *it );
00128         if ( *it == preferred )
00129             button->setChecked( true );
00130         button->setShown( true );
00131     }
00132     connect( m_emailGroup, TQT_SIGNAL( clicked( int ) ), 
00133              this, TQT_SLOT( emailButtonClicked( int ) ) ); 
00134     m_radioLayout->addWidget( m_emailGroup, 0, 0 );
00135     m_emailGroup->setShown( true );
00136     m_mainLayout->invalidate();
00137 }
00138 
00139 
00140 #include "distributionlistentryview.moc"