korganizer

publishdialog.cpp

00001 /*
00002     This file is part of KOrganizer.
00003     Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program 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
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; if not, write to the Free Software
00017     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00018 
00019     As a special exception, permission is given to link this program
00020     with any edition of Qt, and distribute the resulting executable,
00021     without including the source code for Qt in the source distribution.
00022 */
00023 
00024 #include <qlineedit.h>
00025 #include <qpushbutton.h>
00026 #include <kdebug.h>
00027 #include <qlistview.h>
00028 
00029 #include <kglobal.h>
00030 #include <klocale.h>
00031 #ifndef KORG_NOKABC
00032 #include <kabc/addresseedialog.h>
00033 #endif
00034 #include <libkcal/attendee.h>
00035 
00036 #include "koprefs.h"
00037 #include "publishdialog.h"
00038 #include "publishdialog_base.h"
00039 
00040 PublishDialog::PublishDialog( QWidget* parent, const char* name,
00041                               bool modal )
00042   : KDialogBase( parent, name, modal,
00043     i18n("Select Addresses"), Ok|Cancel|Help, Ok, true )
00044 {
00045   mWidget = new PublishDialog_base( this, "PublishFreeBusy" );
00046   setMainWidget( mWidget );
00047   mWidget->mNameLineEdit->setEnabled( false );
00048   mWidget->mEmailLineEdit->setEnabled( false );
00049   connect( mWidget->mAddressListView, SIGNAL( selectionChanged(QListViewItem *) ),
00050            SLOT(updateInput()));
00051   connect( mWidget->mNew, SIGNAL( clicked() ),
00052            SLOT( addItem() ) );
00053   connect( mWidget->mRemove, SIGNAL( clicked() ),
00054            SLOT( removeItem() ) );
00055   connect( mWidget->mSelectAddressee, SIGNAL( clicked() ),
00056            SLOT( openAddressbook() ) );
00057   connect( mWidget->mNameLineEdit, SIGNAL( textChanged(const QString&) ),
00058            SLOT( updateItem() ) );
00059   connect( mWidget->mEmailLineEdit, SIGNAL( textChanged(const QString&) ),
00060            SLOT( updateItem() ) );
00061 }
00062 
00063 PublishDialog::~PublishDialog()
00064 {
00065 }
00066 
00067 void PublishDialog::addAttendee( Attendee *attendee )
00068 {
00069   mWidget->mNameLineEdit->setEnabled( true );
00070   mWidget->mEmailLineEdit->setEnabled( true );
00071   QListViewItem *item = new QListViewItem( mWidget->mAddressListView );
00072   item->setText( 0, attendee->name() );
00073   item->setText( 1, attendee->email() );
00074   mWidget->mAddressListView->insertItem( item );
00075 }
00076 
00077 QString PublishDialog::addresses()
00078 {
00079   QString to = "";
00080   QListViewItem *item;
00081   int i, count;
00082   count = mWidget->mAddressListView->childCount();
00083   for ( i=0; i<count; i++ ) {
00084     item = mWidget->mAddressListView->firstChild();
00085     mWidget->mAddressListView->takeItem( item );
00086     to += item->text( 1 );
00087     if ( i < count-1 ) {
00088       to += ", ";
00089     }
00090   }
00091   return to;
00092 }
00093 
00094 void PublishDialog::addItem()
00095 {
00096   mWidget->mNameLineEdit->setEnabled( true );
00097   mWidget->mEmailLineEdit->setEnabled( true );
00098   QListViewItem *item = new QListViewItem( mWidget->mAddressListView );
00099   mWidget->mAddressListView->insertItem( item );
00100   mWidget->mAddressListView->setSelected( item, true );
00101   mWidget->mNameLineEdit->setText( i18n("(EmptyName)") );
00102   mWidget->mEmailLineEdit->setText( i18n("(EmptyEmail)") );
00103 }
00104 
00105 void PublishDialog::removeItem()
00106 {
00107   QListViewItem *item;
00108   item = mWidget->mAddressListView->selectedItem();
00109   if (!item) return;
00110   mWidget->mAddressListView->takeItem( item );
00111   item = mWidget->mAddressListView->selectedItem();
00112   if ( !item ) {
00113     mWidget->mNameLineEdit->setText( "" );
00114     mWidget->mEmailLineEdit->setText( "" );
00115     mWidget->mNameLineEdit->setEnabled( false );
00116     mWidget->mEmailLineEdit->setEnabled( false );
00117   }
00118   if ( mWidget->mAddressListView->childCount() == 0 ) {
00119     mWidget->mNameLineEdit->setEnabled( false );
00120     mWidget->mEmailLineEdit->setEnabled( false );
00121   }
00122 }
00123 
00124 void PublishDialog::openAddressbook()
00125 {
00126 #ifndef KORG_NOKABC
00127   KABC::Addressee::List addressList;
00128   addressList = KABC::AddresseeDialog::getAddressees( this );
00129   //KABC::Addressee a = KABC::AddresseeDialog::getAddressee(this);
00130   KABC::Addressee a = addressList.first();
00131   if ( !a.isEmpty() ) {
00132     uint i;
00133     for ( i=0; i<addressList.size(); i++ ) {
00134       a = addressList[i];
00135       mWidget->mNameLineEdit->setEnabled( true );
00136       mWidget->mEmailLineEdit->setEnabled( true );
00137       QListViewItem *item = new QListViewItem( mWidget->mAddressListView );
00138       mWidget->mAddressListView->setSelected( item, true );
00139       mWidget->mNameLineEdit->setText( a.realName() );
00140       mWidget->mEmailLineEdit->setText( a.preferredEmail() );
00141       mWidget->mAddressListView->insertItem( item );
00142     }
00143   }
00144 #endif
00145 }
00146 
00147 void PublishDialog::updateItem()
00148 {
00149   QListViewItem *item;
00150   item = mWidget->mAddressListView->selectedItem();
00151   if (!item) return;
00152   item->setText( 0, mWidget->mNameLineEdit->text() );
00153   item->setText( 1, mWidget->mEmailLineEdit->text() );
00154 } 
00155 
00156 void PublishDialog::updateInput()
00157 {
00158   QListViewItem *item;
00159   item = mWidget->mAddressListView->selectedItem();
00160   if (!item) return;
00161   mWidget->mNameLineEdit->setEnabled( true );
00162   mWidget->mEmailLineEdit->setEnabled( true );
00163   QString mail = item->text( 1 );
00164   mWidget->mNameLineEdit->setText( item->text( 0 ) );
00165   mWidget->mEmailLineEdit->setText( mail );
00166 }
00167 
00168 #include "publishdialog.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys