korganizer Library API Documentation

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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, 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 
00048   mWidget->mNameLineEdit->setEnabled( false );
00049   mWidget->mEmailLineEdit->setEnabled( false );
00050   connect( mWidget->mAddressListView, SIGNAL( selectionChanged(QListViewItem *) ),
00051            SLOT(updateInput()));
00052   connect( mWidget->mNew, SIGNAL( clicked() ),
00053            SLOT( addItem() ) );
00054   connect( mWidget->mRemove, SIGNAL( clicked() ),
00055            SLOT( removeItem() ) );
00056   connect( mWidget->mSelectAddressee, SIGNAL( clicked() ),
00057            SLOT( openAddressbook() ) );
00058   connect( mWidget->mNameLineEdit, SIGNAL( textChanged(const QString&) ),
00059            SLOT( updateItem() ) );
00060   connect( mWidget->mEmailLineEdit, SIGNAL( textChanged(const QString&) ),
00061            SLOT( updateItem() ) );
00062 }
00063 
00064 PublishDialog::~PublishDialog()
00065 {
00066 }
00067 
00068 void PublishDialog::addAttendee( Attendee *attendee )
00069 {
00070   mWidget->mNameLineEdit->setEnabled( true );
00071   mWidget->mEmailLineEdit->setEnabled( true );
00072   QListViewItem *item = new QListViewItem( mWidget->mAddressListView );
00073   item->setText( 0, attendee->name() );
00074   item->setText( 1, attendee->email() );
00075   mWidget->mAddressListView->insertItem( item );
00076 }
00077 
00078 QString PublishDialog::addresses()
00079 {
00080   QString to = "";
00081   QListViewItem *item;
00082   int i, count;
00083   count = mWidget->mAddressListView->childCount();
00084   for ( i=0; i<count; i++ ) {
00085     item = mWidget->mAddressListView->firstChild();
00086     mWidget->mAddressListView->takeItem( item );
00087     to += item->text( 1 );
00088     if ( i < count-1 ) {
00089       to += ", ";
00090     }
00091   }
00092   return to;
00093 }
00094 
00095 void PublishDialog::addItem()
00096 {
00097   mWidget->mNameLineEdit->setEnabled( true );
00098   mWidget->mEmailLineEdit->setEnabled( true );
00099   QListViewItem *item = new QListViewItem( mWidget->mAddressListView );
00100   mWidget->mAddressListView->insertItem( item );
00101   mWidget->mAddressListView->setSelected( item, true );
00102   mWidget->mNameLineEdit->setText( i18n("(EmptyName)") );
00103   mWidget->mEmailLineEdit->setText( i18n("(EmptyEmail)") );
00104 }
00105 
00106 void PublishDialog::removeItem()
00107 {
00108   QListViewItem *item;
00109   item = mWidget->mAddressListView->selectedItem();
00110   if (!item) return;
00111   mWidget->mAddressListView->takeItem( item );
00112   item = mWidget->mAddressListView->selectedItem();
00113   if ( !item ) {
00114     mWidget->mNameLineEdit->setText( "" );
00115     mWidget->mEmailLineEdit->setText( "" );
00116     mWidget->mNameLineEdit->setEnabled( false );
00117     mWidget->mEmailLineEdit->setEnabled( false );
00118   }
00119   if ( mWidget->mAddressListView->childCount() == 0 ) {
00120     mWidget->mNameLineEdit->setEnabled( false );
00121     mWidget->mEmailLineEdit->setEnabled( false );
00122   }
00123 }
00124 
00125 void PublishDialog::openAddressbook()
00126 {
00127 #ifndef KORG_NOKABC
00128   KABC::Addressee::List addressList;
00129   addressList = KABC::AddresseeDialog::getAddressees( this );
00130   //KABC::Addressee a = KABC::AddresseeDialog::getAddressee(this);
00131   KABC::Addressee a = addressList.first();
00132   if ( !a.isEmpty() ) {
00133     uint i;
00134     for ( i=0; i<addressList.size(); i++ ) {
00135       a = addressList[i];
00136       mWidget->mNameLineEdit->setEnabled( true );
00137       mWidget->mEmailLineEdit->setEnabled( true );
00138       QListViewItem *item = new QListViewItem( mWidget->mAddressListView );
00139       mWidget->mAddressListView->setSelected( item, true );
00140       mWidget->mNameLineEdit->setText( a.realName() );
00141       mWidget->mEmailLineEdit->setText( a.preferredEmail() );
00142       mWidget->mAddressListView->insertItem( item );
00143     }
00144   }
00145 #endif
00146 }
00147 
00148 void PublishDialog::updateItem()
00149 {
00150   QListViewItem *item;
00151   item = mWidget->mAddressListView->selectedItem();
00152   if (!item) return;
00153   item->setText( 0, mWidget->mNameLineEdit->text() );
00154   item->setText( 1, mWidget->mEmailLineEdit->text() );
00155 } 
00156 
00157 void PublishDialog::updateInput()
00158 {
00159   QListViewItem *item;
00160   item = mWidget->mAddressListView->selectedItem();
00161   if (!item) return;
00162   mWidget->mNameLineEdit->setEnabled( true );
00163   mWidget->mEmailLineEdit->setEnabled( true );
00164   QString mail = item->text( 1 );
00165   mWidget->mNameLineEdit->setText( item->text( 0 ) );
00166   mWidget->mEmailLineEdit->setText( mail );
00167 }
00168 
00169 #include "publishdialog.moc"
KDE Logo
This file is part of the documentation for korganizer Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 23 22:45:27 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003