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 00028 #include <kglobal.h> 00029 #include <klocale.h> 00030 #ifndef KORG_NOKABC 00031 #include <kabc/addresseedialog.h> 00032 #endif 00033 00034 #include "koprefs.h" 00035 #include "publishdialog.h" 00036 #include "publishdialog_base.h" 00037 00038 PublishDialog::PublishDialog( QWidget* parent, const char* name, 00039 bool modal ) 00040 : KDialogBase( parent, name, modal, 00041 i18n("Select Addresses"), Ok|Cancel|Help, Ok, true ) 00042 { 00043 mWidget = new PublishDialog_base( this, "PublishFreeBusy" ); 00044 setMainWidget( mWidget ); 00045 00046 mWidget->mNameLineEdit->setEnabled( false ); 00047 mWidget->mEmailLineEdit->setEnabled( false ); 00048 connect( mWidget->mAddressListView, SIGNAL( selectionChanged(QListViewItem *) ), 00049 SLOT(updateInput())); 00050 connect( mWidget->mNew, SIGNAL( clicked() ), 00051 SLOT( addItem() ) ); 00052 connect( mWidget->mRemove, SIGNAL( clicked() ), 00053 SLOT( removeItem() ) ); 00054 connect( mWidget->mSelectAddressee, SIGNAL( clicked() ), 00055 SLOT( openAddressbook() ) ); 00056 connect( mWidget->mNameLineEdit, SIGNAL( textChanged(const QString&) ), 00057 SLOT( updateItem() ) ); 00058 connect( mWidget->mEmailLineEdit, SIGNAL( textChanged(const QString&) ), 00059 SLOT( updateItem() ) ); 00060 } 00061 00062 PublishDialog::~PublishDialog() 00063 { 00064 } 00065 00066 void PublishDialog::addAttendee( Attendee *attendee ) 00067 { 00068 mWidget->mNameLineEdit->setEnabled( true ); 00069 mWidget->mEmailLineEdit->setEnabled( true ); 00070 QListViewItem *item = new QListViewItem( mWidget->mAddressListView ); 00071 item->setText( 0, attendee->name() ); 00072 item->setText( 1, attendee->email() ); 00073 mWidget->mAddressListView->insertItem( item ); 00074 } 00075 00076 QString PublishDialog::addresses() 00077 { 00078 QString to = ""; 00079 QListViewItem *item; 00080 int i, count; 00081 count = mWidget->mAddressListView->childCount(); 00082 for ( i=0; i<count; i++ ) { 00083 item = mWidget->mAddressListView->firstChild(); 00084 mWidget->mAddressListView->takeItem( item ); 00085 to += item->text( 1 ); 00086 if ( i < count-1 ) { 00087 to += ", "; 00088 } 00089 } 00090 return to; 00091 } 00092 00093 void PublishDialog::addItem() 00094 { 00095 mWidget->mNameLineEdit->setEnabled( true ); 00096 mWidget->mEmailLineEdit->setEnabled( true ); 00097 QListViewItem *item = new QListViewItem( mWidget->mAddressListView ); 00098 mWidget->mAddressListView->insertItem( item ); 00099 mWidget->mAddressListView->setSelected( item, true ); 00100 mWidget->mNameLineEdit->setText( i18n("(EmptyName)") ); 00101 mWidget->mEmailLineEdit->setText( i18n("(EmptyEmail)") ); 00102 } 00103 00104 void PublishDialog::removeItem() 00105 { 00106 QListViewItem *item; 00107 item = mWidget->mAddressListView->selectedItem(); 00108 if (!item) return; 00109 mWidget->mAddressListView->takeItem( item ); 00110 item = mWidget->mAddressListView->selectedItem(); 00111 if ( !item ) { 00112 mWidget->mNameLineEdit->setText( "" ); 00113 mWidget->mEmailLineEdit->setText( "" ); 00114 mWidget->mNameLineEdit->setEnabled( false ); 00115 mWidget->mEmailLineEdit->setEnabled( false ); 00116 } 00117 if ( mWidget->mAddressListView->childCount() == 0 ) { 00118 mWidget->mNameLineEdit->setEnabled( false ); 00119 mWidget->mEmailLineEdit->setEnabled( false ); 00120 } 00121 } 00122 00123 void PublishDialog::openAddressbook() 00124 { 00125 #ifndef KORG_NOKABC 00126 KABC::Addressee::List addressList; 00127 addressList = KABC::AddresseeDialog::getAddressees( this ); 00128 //KABC::Addressee a = KABC::AddresseeDialog::getAddressee(this); 00129 KABC::Addressee a = addressList.first(); 00130 if ( !a.isEmpty() ) { 00131 uint i; 00132 for ( i=0; i<addressList.size(); i++ ) { 00133 a = addressList[i]; 00134 mWidget->mNameLineEdit->setEnabled( true ); 00135 mWidget->mEmailLineEdit->setEnabled( true ); 00136 QListViewItem *item = new QListViewItem( mWidget->mAddressListView ); 00137 mWidget->mAddressListView->setSelected( item, true ); 00138 mWidget->mNameLineEdit->setText( a.realName() ); 00139 mWidget->mEmailLineEdit->setText( a.preferredEmail() ); 00140 mWidget->mAddressListView->insertItem( item ); 00141 } 00142 } 00143 #endif 00144 } 00145 00146 void PublishDialog::updateItem() 00147 { 00148 QListViewItem *item; 00149 item = mWidget->mAddressListView->selectedItem(); 00150 if (!item) return; 00151 item->setText( 0, mWidget->mNameLineEdit->text() ); 00152 item->setText( 1, mWidget->mEmailLineEdit->text() ); 00153 } 00154 00155 void PublishDialog::updateInput() 00156 { 00157 QListViewItem *item; 00158 item = mWidget->mAddressListView->selectedItem(); 00159 if (!item) return; 00160 mWidget->mNameLineEdit->setEnabled( true ); 00161 mWidget->mEmailLineEdit->setEnabled( true ); 00162 QString mail = item->text( 1 ); 00163 mWidget->mNameLineEdit->setText( item->text( 0 ) ); 00164 mWidget->mEmailLineEdit->setText( mail ); 00165 } 00166 00167 #include "publishdialog.moc"
KDE Logo
This file is part of the documentation for korganizer Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jul 28 23:58:14 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003