kaddressbook

distributionlistentryview.cpp
1 #include "distributionlistentryview.h"
2 #include "imagewidget.h"
3 #include <interfaces/core.h>
4 
5 #include <libtdepim/resourceabc.h>
6 
7 #include <tdeabc/addressbook.h>
8 #include <tdeabc/resource.h>
9 
10 #include <kdialog.h>
11 #include <kiconloader.h>
12 #include <tdelocale.h>
13 #include <kurllabel.h>
14 
15 #include <tqbuttongroup.h>
16 #include <tqcombobox.h>
17 #include <tqlabel.h>
18 #include <tqlayout.h>
19 #include <tqradiobutton.h>
20 #include <tqstringlist.h>
21 #include <tqvbuttongroup.h>
22 
23 KAB::DistributionListEntryView::DistributionListEntryView( KAB::Core* core, TQWidget* parent ) : TQWidget( parent ), m_core( core ), m_emailGroup( 0 )
24 {
25  m_mainLayout = new TQVBoxLayout( this );
26  m_mainLayout->setSpacing( KDialog::spacingHint() );
27  m_mainLayout->setMargin( KDialog::marginHint() );
28 
29  TQBoxLayout* headerLayout = new TQHBoxLayout;
30  headerLayout->setSpacing( KDialog::spacingHint() * 3 );
31 
32  m_imageLabel = new TQLabel( this );
33  m_imageLabel->setAutoResize( true );
34  headerLayout->addWidget( m_imageLabel, 0, TQt::AlignTop );
35 
36  m_addresseeLabel = new TQLabel( this );
37  headerLayout->addWidget( m_addresseeLabel, 0, TQt::AlignTop );
38  headerLayout->addStretch();
39 
40  m_mainLayout->addItem( headerLayout );
41 
42  TQBoxLayout* distLayout = new TQHBoxLayout;
43  distLayout->setSpacing( KDialog::spacingHint() );
44 
45  TQLabel* distLabel = new TQLabel( this );
46  distLabel->setText( i18n( "<b>Distribution list:</b>" ) );
47  distLabel->setAlignment( TQt::SingleLine );
48  distLayout->addWidget( distLabel );
49 
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 );
57 
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 );
62 
63  TQBoxLayout* emailLayout = new TQHBoxLayout;
64  emailLayout->setSpacing( KDialog::spacingHint() );
65  emailLayout->addSpacing( 30 );
66 
67  m_radioLayout = new TQGridLayout;
68  emailLayout->addItem( m_radioLayout );
69  emailLayout->addStretch();
70  m_mainLayout->addItem( emailLayout );
71 
72  TQBoxLayout* resourceLayout = new TQHBoxLayout;
73  resourceLayout->setSpacing( KDialog::spacingHint() );
74  m_resourceLabel = new TQLabel( this );
75  resourceLayout->addWidget( m_resourceLabel );
76  resourceLayout->addStretch();
77 
78  m_mainLayout->addItem( resourceLayout );
79  m_mainLayout->addStretch();
80 }
81 
82 void KAB::DistributionListEntryView::emailButtonClicked( int id )
83 {
84  const TQString email = m_idToEmail[ id ];
85  if ( m_entry.email == email )
86  return;
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 );
91 }
92 
93 void KAB::DistributionListEntryView::clear()
94 {
95  setEntry( KPIM::DistributionList(), KPIM::DistributionList::Entry() );
96 }
97 
98 void KAB::DistributionListEntryView::setEntry( const KPIM::DistributionList& list, const KPIM::DistributionList::Entry& entry )
99 {
100  m_list = list;
101  m_entry = entry;
102 
103  delete m_emailGroup;
104  m_emailGroup = 0;
105 
106  TQPixmap pixmap;
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 );
114 
115  m_emailGroup = new TQVButtonGroup( this );
116  m_emailGroup->setFlat( true );
117  m_emailGroup->setExclusive( true );
118  m_emailGroup->setFrameShape( TQFrame::NoFrame );
119 
120  const TQString preferred = m_entry.email.isNull() ? m_entry.addressee.preferredEmail() : m_entry.email;
121  const TQStringList mails = m_entry.addressee.emails();
122  m_idToEmail.clear();
123  for ( TQStringList::ConstIterator it = mails.begin(); it != mails.end(); ++it )
124  {
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 );
131  }
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();
137 }
138 
139 
140 #include "distributionlistentryview.moc"