1 #include "distributionlistentryview.h"
2 #include "imagewidget.h"
3 #include <interfaces/core.h>
5 #include <libtdepim/resourceabc.h>
7 #include <tdeabc/addressbook.h>
8 #include <tdeabc/resource.h>
11 #include <kiconloader.h>
12 #include <tdelocale.h>
13 #include <kurllabel.h>
15 #include <tqbuttongroup.h>
16 #include <tqcombobox.h>
19 #include <tqradiobutton.h>
20 #include <tqstringlist.h>
21 #include <tqvbuttongroup.h>
23 KAB::DistributionListEntryView::DistributionListEntryView( KAB::Core* core, TQWidget* parent ) : TQWidget( parent ), m_core( core ), m_emailGroup( 0 )
25 m_mainLayout =
new TQVBoxLayout(
this );
26 m_mainLayout->setSpacing( KDialog::spacingHint() );
27 m_mainLayout->setMargin( KDialog::marginHint() );
29 TQBoxLayout* headerLayout =
new TQHBoxLayout;
30 headerLayout->setSpacing( KDialog::spacingHint() * 3 );
32 m_imageLabel =
new TQLabel(
this );
33 m_imageLabel->setAutoResize(
true );
34 headerLayout->addWidget( m_imageLabel, 0, TQt::AlignTop );
36 m_addresseeLabel =
new TQLabel(
this );
37 headerLayout->addWidget( m_addresseeLabel, 0, TQt::AlignTop );
38 headerLayout->addStretch();
40 m_mainLayout->addItem( headerLayout );
42 TQBoxLayout* distLayout =
new TQHBoxLayout;
43 distLayout->setSpacing( KDialog::spacingHint() );
45 TQLabel* distLabel =
new TQLabel(
this );
46 distLabel->setText( i18n(
"<b>Distribution list:</b>" ) );
47 distLabel->setAlignment( TQt::SingleLine );
48 distLayout->addWidget( distLabel );
50 m_distListLabel =
new KURLLabel(
this );
51 distLabel->setBuddy( m_distListLabel );
52 connect( m_distListLabel, TQ_SIGNAL( leftClickedURL(
const TQString& ) ),
53 this, TQ_SIGNAL( distributionListClicked(
const TQString& ) ) );
54 distLayout->addWidget( m_distListLabel );
55 distLayout->addStretch();
56 m_mainLayout->addItem( distLayout );
58 TQLabel* emailLabel =
new TQLabel(
this );
59 emailLabel->setText( i18n(
"<b>Email address to use in this list:</b>" ) );
60 emailLabel->setAlignment( TQt::SingleLine );
61 m_mainLayout->addWidget( emailLabel );
63 TQBoxLayout* emailLayout =
new TQHBoxLayout;
64 emailLayout->setSpacing( KDialog::spacingHint() );
65 emailLayout->addSpacing( 30 );
67 m_radioLayout =
new TQGridLayout;
68 emailLayout->addItem( m_radioLayout );
69 emailLayout->addStretch();
70 m_mainLayout->addItem( emailLayout );
72 TQBoxLayout* resourceLayout =
new TQHBoxLayout;
73 resourceLayout->setSpacing( KDialog::spacingHint() );
74 m_resourceLabel =
new TQLabel(
this );
75 resourceLayout->addWidget( m_resourceLabel );
76 resourceLayout->addStretch();
78 m_mainLayout->addItem( resourceLayout );
79 m_mainLayout->addStretch();
82 void KAB::DistributionListEntryView::emailButtonClicked(
int id )
84 const TQString email = m_idToEmail[ id ];
85 if ( m_entry.email == email )
87 m_list.removeEntry( m_entry.addressee, m_entry.email );
88 m_entry.email = email;
89 m_list.insertEntry( m_entry.addressee, m_entry.email );
90 m_core->addressBook()->insertAddressee( m_list );
93 void KAB::DistributionListEntryView::clear()
95 setEntry( KPIM::DistributionList(), KPIM::DistributionList::Entry() );
98 void KAB::DistributionListEntryView::setEntry(
const KPIM::DistributionList& list,
const KPIM::DistributionList::Entry& entry )
107 pixmap.convertFromImage( m_entry.addressee.photo().data() );
108 m_imageLabel->setPixmap( pixmap.isNull() ? TDEGlobal::iconLoader()->loadIcon(
"preferences-desktop-personal", TDEIcon::Desktop ) : pixmap );
109 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() ) );
110 m_distListLabel->setURL( m_list.name() );
111 m_distListLabel->setText( m_list.name() );
112 m_resourceLabel->setText( i18n(
"<b>Address book:</b> %1" ).arg( m_entry.addressee.resource() ? m_entry.addressee.resource()->resourceName() : TQString() ) );
113 m_resourceLabel->setAlignment( TQt::SingleLine );
115 m_emailGroup =
new TQVButtonGroup(
this );
116 m_emailGroup->setFlat(
true );
117 m_emailGroup->setExclusive(
true );
118 m_emailGroup->setFrameShape( TQFrame::NoFrame );
120 const TQString preferred = m_entry.email.isNull() ? m_entry.addressee.preferredEmail() : m_entry.email;
121 const TQStringList mails = m_entry.addressee.emails();
123 for ( TQStringList::ConstIterator it = mails.begin(); it != mails.end(); ++it )
125 TQRadioButton* button =
new TQRadioButton( m_emailGroup );
126 button->setText( *it );
127 m_idToEmail.insert( m_emailGroup->insert( button ), *it );
128 if ( *it == preferred )
129 button->setChecked(
true );
130 button->setShown(
true );
132 connect( m_emailGroup, TQ_SIGNAL( clicked(
int ) ),
133 this, TQ_SLOT( emailButtonClicked(
int ) ) );
134 m_radioLayout->addWidget( m_emailGroup, 0, 0 );
135 m_emailGroup->setShown(
true );
136 m_mainLayout->invalidate();
140 #include "distributionlistentryview.moc"