• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeabc
 

tdeabc

distributionlisteditor.cpp

00001 /*
00002     This file is part of libtdeabc.
00003     Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public License
00016     along with this library; see the file COPYING.LIB.  If not, write to
00017     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018     Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include <tqlistview.h>
00022 #include <tqlayout.h>
00023 #include <tqpushbutton.h>
00024 #include <tqcombobox.h>
00025 #include <tqbuttongroup.h>
00026 #include <tqradiobutton.h>
00027 
00028 #include <kinputdialog.h>
00029 #include <tdelocale.h>
00030 #include <kdebug.h>
00031 
00032 #include "addressbook.h"
00033 #include "addresseedialog.h"
00034 #include "distributionlist.h"
00035 
00036 #include "distributionlisteditor.h"
00037 #include "distributionlisteditor.moc"
00038 
00039 using namespace TDEABC;
00040 
00041 EmailSelectDialog::EmailSelectDialog( const TQStringList &emails, const TQString &current,
00042                                       TQWidget *parent ) :
00043   KDialogBase( KDialogBase::Plain, i18n("Select Email Address"), Ok, Ok,
00044                parent )
00045 {
00046   TQFrame *topFrame = plainPage();
00047   TQBoxLayout *topLayout = new TQVBoxLayout( topFrame );
00048 
00049   mButtonGroup = new TQButtonGroup( 1, Qt::Horizontal, i18n("Email Addresses"),
00050                                    topFrame );
00051   mButtonGroup->setRadioButtonExclusive( true );
00052   topLayout->addWidget( mButtonGroup );
00053 
00054   TQStringList::ConstIterator it;
00055   for( it = emails.begin(); it != emails.end(); ++it ) {
00056     TQRadioButton *button = new TQRadioButton( *it, mButtonGroup );
00057     if ( (*it) == current ) {
00058       button->setDown( true );
00059     }
00060   }
00061 }
00062 
00063 TQString EmailSelectDialog::selected()
00064 {
00065   TQButton *button = mButtonGroup->selected();
00066   if ( button ) return button->text();
00067   return TQString::null;
00068 }
00069 
00070 TQString EmailSelectDialog::getEmail( const TQStringList &emails, const TQString &current,
00071                                      TQWidget *parent )
00072 {
00073   EmailSelectDialog *dlg = new EmailSelectDialog( emails, current, parent );
00074   dlg->exec();
00075 
00076   TQString result = dlg->selected();
00077 
00078   delete dlg;
00079 
00080   return result;
00081 }
00082 
00083 class EditEntryItem : public TQListViewItem
00084 {
00085   public:
00086     EditEntryItem( TQListView *parent, const Addressee &addressee,
00087                const TQString &email=TQString::null ) :
00088       TQListViewItem( parent ),
00089       mAddressee( addressee ),
00090       mEmail( email )
00091     {
00092       setText( 0, addressee.realName() );
00093       if( email.isEmpty() ) {
00094         setText( 1, addressee.preferredEmail() );
00095         setText( 2, i18n("Yes") );
00096       } else {
00097         setText( 1, email );
00098         setText( 2, i18n("No") );
00099       }
00100     }
00101 
00102     Addressee addressee() const
00103     {
00104       return mAddressee;
00105     }
00106 
00107     TQString email() const
00108     {
00109       return mEmail;
00110     }
00111 
00112   private:
00113     Addressee mAddressee;
00114     TQString mEmail;
00115 };
00116 
00117 DistributionListEditor::DistributionListEditor( AddressBook *addressBook, TQWidget *parent) :
00118   TQWidget( parent ),
00119   mAddressBook( addressBook )
00120 {
00121   kdDebug(5700) << "DistributionListEditor()" << endl;
00122 
00123   TQBoxLayout *topLayout = new TQVBoxLayout( this );
00124   topLayout->setMargin( KDialog::marginHint() );
00125   topLayout->setSpacing( KDialog::spacingHint() );
00126 
00127   TQBoxLayout *nameLayout = new TQHBoxLayout( topLayout) ;
00128 
00129   mNameCombo = new TQComboBox( this );
00130   nameLayout->addWidget( mNameCombo );
00131   connect( mNameCombo, TQT_SIGNAL( activated( int ) ), TQT_SLOT( updateEntryView() ) );
00132 
00133   newButton = new TQPushButton( i18n("New List"), this );
00134   nameLayout->addWidget( newButton );
00135   connect( newButton, TQT_SIGNAL( clicked() ), TQT_SLOT( newList() ) );
00136 
00137   removeButton = new TQPushButton( i18n("Remove List"), this );
00138   nameLayout->addWidget( removeButton );
00139   connect( removeButton, TQT_SIGNAL( clicked() ), TQT_SLOT( removeList() ) );
00140 
00141   mEntryView = new TQListView( this );
00142   mEntryView->addColumn( i18n("Name") );
00143   mEntryView->addColumn( i18n("Email") );
00144   mEntryView->addColumn( i18n("Use Preferred") );
00145   topLayout->addWidget( mEntryView );
00146   connect(mEntryView,TQT_SIGNAL(selectionChanged ()),this, TQT_SLOT(slotSelectionEntryViewChanged()));
00147 
00148   changeEmailButton = new TQPushButton( i18n("Change Email"), this );
00149   topLayout->addWidget( changeEmailButton );
00150   connect( changeEmailButton, TQT_SIGNAL( clicked() ), TQT_SLOT( changeEmail() ) );
00151 
00152   removeEntryButton = new TQPushButton( i18n("Remove Entry"), this );
00153   topLayout->addWidget( removeEntryButton );
00154   connect( removeEntryButton, TQT_SIGNAL( clicked() ), TQT_SLOT( removeEntry() ) );
00155 
00156   addEntryButton = new TQPushButton( i18n("Add Entry"), this );
00157   topLayout->addWidget( addEntryButton );
00158   connect( addEntryButton, TQT_SIGNAL( clicked() ), TQT_SLOT( addEntry() ) );
00159 
00160   mAddresseeView = new TQListView( this );
00161   mAddresseeView->addColumn( i18n("Name") );
00162   mAddresseeView->addColumn( i18n("Preferred Email") );
00163   topLayout->addWidget( mAddresseeView );
00164 
00165 
00166   connect(mAddresseeView,TQT_SIGNAL(selectionChanged ()),this, TQT_SLOT(slotSelectionAddresseeViewChanged()));
00167 
00168   mManager = new DistributionListManager( mAddressBook );
00169   mManager->load();
00170 
00171   updateAddresseeView();
00172   updateNameCombo();
00173   removeButton->setEnabled(!mManager->listNames().isEmpty());
00174 }
00175 
00176 DistributionListEditor::~DistributionListEditor()
00177 {
00178   kdDebug(5700) << "~DistributionListEditor()" << endl;
00179 
00180   mManager->save();
00181   delete mManager;
00182 }
00183 
00184 void DistributionListEditor::slotSelectionEntryViewChanged()
00185 {
00186     EditEntryItem *entryItem = dynamic_cast<EditEntryItem *>( mEntryView->selectedItem() );
00187     bool state = (entryItem != 0L);
00188 
00189     changeEmailButton->setEnabled(state);
00190     removeEntryButton->setEnabled(state);
00191 }
00192 
00193 void DistributionListEditor::newList()
00194 {
00195   bool ok = false;
00196   TQString name = KInputDialog::getText( i18n("New Distribution List"),
00197                                         i18n("Please enter name:"),
00198                                         TQString::null, &ok, this );
00199   if ( !ok )
00200     return;
00201 
00202   new DistributionList( mManager, name );
00203 
00204   mNameCombo->insertItem( name );
00205   removeButton->setEnabled(true);
00206   updateEntryView();
00207 }
00208 
00209 void DistributionListEditor::removeList()
00210 {
00211   mManager->remove( mManager->list( mNameCombo->currentText() ) );
00212   mNameCombo->removeItem( mNameCombo->currentItem() );
00213   removeButton->setEnabled(!mManager->listNames().isEmpty());
00214   addEntryButton->setEnabled( !mNameCombo->currentText().isEmpty());
00215   updateEntryView();
00216 }
00217 
00218 void DistributionListEditor::addEntry()
00219 {
00220   AddresseeItem *addresseeItem =
00221       dynamic_cast<AddresseeItem *>( mAddresseeView->selectedItem() );
00222 
00223   if( !addresseeItem ) {
00224     kdDebug(5700) << "DLE::addEntry(): No addressee selected." << endl;
00225     return;
00226   }
00227 
00228   DistributionList *list = mManager->list( mNameCombo->currentText() );
00229   if ( !list ) {
00230     kdDebug(5700) << "DLE::addEntry(): No dist list '" << mNameCombo->currentText() << "'" << endl;
00231     return;
00232   }
00233 
00234   list->insertEntry( addresseeItem->addressee() );
00235   updateEntryView();
00236   slotSelectionAddresseeViewChanged();
00237 }
00238 
00239 void DistributionListEditor::removeEntry()
00240 {
00241   DistributionList *list = mManager->list( mNameCombo->currentText() );
00242   if ( !list ) return;
00243 
00244   EditEntryItem *entryItem =
00245       dynamic_cast<EditEntryItem *>( mEntryView->selectedItem() );
00246   if ( !entryItem ) return;
00247 
00248   list->removeEntry( entryItem->addressee(), entryItem->email() );
00249   delete entryItem;
00250 }
00251 
00252 void DistributionListEditor::changeEmail()
00253 {
00254   DistributionList *list = mManager->list( mNameCombo->currentText() );
00255   if ( !list ) return;
00256 
00257   EditEntryItem *entryItem =
00258       dynamic_cast<EditEntryItem *>( mEntryView->selectedItem() );
00259   if ( !entryItem ) return;
00260 
00261   TQString email = EmailSelectDialog::getEmail( entryItem->addressee().emails(),
00262                                                entryItem->email(), this );
00263   list->removeEntry( entryItem->addressee(), entryItem->email() );
00264   list->insertEntry( entryItem->addressee(), email );
00265 
00266   updateEntryView();
00267 }
00268 
00269 void DistributionListEditor::updateEntryView()
00270 {
00271   DistributionList *list = mManager->list( mNameCombo->currentText() );
00272   if ( !list ) return;
00273 
00274   mEntryView->clear();
00275   DistributionList::Entry::List entries = list->entries();
00276   DistributionList::Entry::List::ConstIterator it;
00277   for( it = entries.begin(); it != entries.end(); ++it ) {
00278     new EditEntryItem( mEntryView, (*it).addressee, (*it).email );
00279   }
00280    EditEntryItem *entryItem = dynamic_cast<EditEntryItem *>( mEntryView->selectedItem() );
00281    bool state = (entryItem != 0L);
00282 
00283    changeEmailButton->setEnabled(state);
00284    removeEntryButton->setEnabled(state);
00285 }
00286 
00287 void DistributionListEditor::updateAddresseeView()
00288 {
00289   mAddresseeView->clear();
00290 
00291   AddressBook::Iterator it;
00292   for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) {
00293     new AddresseeItem( mAddresseeView, *it );
00294   }
00295 }
00296 
00297 void DistributionListEditor::updateNameCombo()
00298 {
00299   mNameCombo->insertStringList( mManager->listNames() );
00300 
00301   updateEntryView();
00302 }
00303 
00304 void DistributionListEditor::slotSelectionAddresseeViewChanged()
00305 {
00306     AddresseeItem *addresseeItem =
00307         dynamic_cast<AddresseeItem *>( mAddresseeView->selectedItem() );
00308     bool state = (addresseeItem != 0L);
00309     addEntryButton->setEnabled( state && !mNameCombo->currentText().isEmpty());
00310 }

tdeabc

Skip menu "tdeabc"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeabc

Skip menu "tdeabc"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeabc by doxygen 1.6.3
This website is maintained by Timothy Pearson.