TDE personal information management applications
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
5.1KB

  1. #include "distributionlistentryview.h"
  2. #include "imagewidget.h"
  3. #include <interfaces/core.h>
  4. #include <libtdepim/resourceabc.h>
  5. #include <kabc/addressbook.h>
  6. #include <kabc/resource.h>
  7. #include <kdialog.h>
  8. #include <kiconloader.h>
  9. #include <klocale.h>
  10. #include <kurllabel.h>
  11. #include <tqbuttongroup.h>
  12. #include <tqcombobox.h>
  13. #include <tqlabel.h>
  14. #include <tqlayout.h>
  15. #include <tqradiobutton.h>
  16. #include <tqstringlist.h>
  17. #include <tqvbuttongroup.h>
  18. KAB::DistributionListEntryView::DistributionListEntryView( KAB::Core* core, TQWidget* parent ) : TQWidget( parent ), m_core( core ), m_emailGroup( 0 )
  19. {
  20. m_mainLayout = new TQVBoxLayout( this );
  21. m_mainLayout->setSpacing( KDialog::spacingHint() );
  22. m_mainLayout->setMargin( KDialog::marginHint() );
  23. TQBoxLayout* headerLayout = new TQHBoxLayout;
  24. headerLayout->setSpacing( KDialog::spacingHint() * 3 );
  25. m_imageLabel = new TQLabel( this );
  26. m_imageLabel->setAutoResize( true );
  27. headerLayout->addWidget( m_imageLabel, 0, TQt::AlignTop );
  28. m_addresseeLabel = new TQLabel( this );
  29. headerLayout->addWidget( m_addresseeLabel, 0, TQt::AlignTop );
  30. headerLayout->addStretch();
  31. m_mainLayout->addItem( headerLayout );
  32. TQBoxLayout* distLayout = new TQHBoxLayout;
  33. distLayout->setSpacing( KDialog::spacingHint() );
  34. TQLabel* distLabel = new TQLabel( this );
  35. distLabel->setText( i18n( "<b>Distribution list:</b>" ) );
  36. distLabel->tqsetAlignment( TQt::SingleLine );
  37. distLayout->addWidget( distLabel );
  38. m_distListLabel = new KURLLabel( this );
  39. distLabel->setBuddy( m_distListLabel );
  40. connect( m_distListLabel, TQT_SIGNAL( leftClickedURL( const TQString& ) ),
  41. this, TQT_SIGNAL( distributionListClicked( const TQString& ) ) );
  42. distLayout->addWidget( m_distListLabel );
  43. distLayout->addStretch();
  44. m_mainLayout->addItem( distLayout );
  45. TQLabel* emailLabel = new TQLabel( this );
  46. emailLabel->setText( i18n( "<b>Email address to use in this list:</b>" ) );
  47. emailLabel->tqsetAlignment( TQt::SingleLine );
  48. m_mainLayout->addWidget( emailLabel );
  49. TQBoxLayout* emailLayout = new TQHBoxLayout;
  50. emailLayout->setSpacing( KDialog::spacingHint() );
  51. emailLayout->addSpacing( 30 );
  52. m_radioLayout = new TQGridLayout;
  53. emailLayout->addItem( m_radioLayout );
  54. emailLayout->addStretch();
  55. m_mainLayout->addItem( emailLayout );
  56. TQBoxLayout* resourceLayout = new TQHBoxLayout;
  57. resourceLayout->setSpacing( KDialog::spacingHint() );
  58. m_resourceLabel = new TQLabel( this );
  59. resourceLayout->addWidget( m_resourceLabel );
  60. resourceLayout->addStretch();
  61. m_mainLayout->addItem( resourceLayout );
  62. m_mainLayout->addStretch();
  63. }
  64. void KAB::DistributionListEntryView::emailButtonClicked( int id )
  65. {
  66. const TQString email = m_idToEmail[ id ];
  67. if ( m_entry.email == email )
  68. return;
  69. m_list.removeEntry( m_entry.addressee, m_entry.email );
  70. m_entry.email = email;
  71. m_list.insertEntry( m_entry.addressee, m_entry.email );
  72. m_core->addressBook()->insertAddressee( m_list );
  73. }
  74. void KAB::DistributionListEntryView::clear()
  75. {
  76. setEntry( KPIM::DistributionList(), KPIM::DistributionList::Entry() );
  77. }
  78. void KAB::DistributionListEntryView::setEntry( const KPIM::DistributionList& list, const KPIM::DistributionList::Entry& entry )
  79. {
  80. m_list = list;
  81. m_entry = entry;
  82. delete m_emailGroup;
  83. m_emailGroup = 0;
  84. TQPixmap pixmap;
  85. pixmap.convertFromImage( m_entry.addressee.photo().data() );
  86. m_imageLabel->setPixmap( pixmap.isNull() ? KGlobal::iconLoader()->loadIcon( "personal", KIcon::Desktop ) : pixmap );
  87. m_addresseeLabel->setText( i18n( "Formatted name, role, organization", "<qt><h2>%1</h2><p>%2<br/>%3</p></qt>" ).tqarg( m_entry.addressee.formattedName(), m_entry.addressee.role(), m_entry.addressee.organization() ) );
  88. m_distListLabel->setURL( m_list.name() );
  89. m_distListLabel->setText( m_list.name() );
  90. m_resourceLabel->setText( i18n( "<b>Address book:</b> %1" ).tqarg( m_entry.addressee.resource() ? m_entry.addressee.resource()->resourceName() : TQString() ) );
  91. m_resourceLabel->tqsetAlignment( TQt::SingleLine );
  92. m_emailGroup = new TQVButtonGroup( this );
  93. m_emailGroup->setFlat( true );
  94. m_emailGroup->setExclusive( true );
  95. m_emailGroup->setFrameShape( TQFrame::NoFrame );
  96. const TQString preferred = m_entry.email.isNull() ? m_entry.addressee.preferredEmail() : m_entry.email;
  97. const TQStringList mails = m_entry.addressee.emails();
  98. m_idToEmail.clear();
  99. for ( TQStringList::ConstIterator it = mails.begin(); it != mails.end(); ++it )
  100. {
  101. TQRadioButton* button = new TQRadioButton( m_emailGroup );
  102. button->setText( *it );
  103. m_idToEmail.insert( m_emailGroup->insert( button ), *it );
  104. if ( *it == preferred )
  105. button->setChecked( true );
  106. button->setShown( true );
  107. }
  108. connect( m_emailGroup, TQT_SIGNAL( clicked( int ) ),
  109. this, TQT_SLOT( emailButtonClicked( int ) ) );
  110. m_radioLayout->addWidget( m_emailGroup, 0, 0 );
  111. m_emailGroup->setShown( true );
  112. m_mainLayout->tqinvalidate();
  113. }
  114. #include "distributionlistentryview.moc"