00001
00002 #include "composemail.h"
00003
00004
00005 #include <opie2/ocontactaccess.h>
00006 #include <opie2/opimcontact.h>
00007 #include <opie2/oresource.h>
00008 #include <qpe/qpeapplication.h>
00009
00010
00011 #include <qpushbutton.h>
00012 #include <qmessagebox.h>
00013 #include <qlistbox.h>
00014
00015
00016 #include <stdlib.h>
00017
00018 AddressPicker::AddressPicker( QWidget *parent, const char *name, bool modal, WFlags flags )
00019 : AddressPickerUI( parent, name, modal, flags )
00020 {
00021 okButton->setIconSet( Opie::Core::OResource::loadPixmap( "enter", Opie::Core::OResource::SmallIcon ) );
00022 cancelButton->setIconSet( Opie::Core::OResource::loadPixmap( "editdelete", Opie::Core::OResource::SmallIcon ) );
00023
00024 connect(okButton, SIGNAL(clicked()), SLOT(accept()));
00025 connect(cancelButton, SIGNAL(clicked()), SLOT(close()));
00026 Opie::OPimContactAccess::List::Iterator it;
00027
00028 QString lineEmail, lineName, contactLine;
00029
00030 Opie::OPimContactAccess m_contactdb("opiemail");
00031
00032 QStringList mails;
00033 QString pre,suf;
00034 Opie::OPimContactAccess::List m_list = m_contactdb.sorted( true, 0, 0, 0 );
00035 for ( it = m_list.begin(); it != m_list.end(); ++it )
00036 {
00037 if ((*it).defaultEmail().length()!=0)
00038 {
00039 mails = (*it).emailList();
00040 if ((*it).fileAs().length()>0)
00041 {
00042 pre = "\""+(*it).firstName()+" "+(*it).lastName()+"\" <";
00043 suf = ">";
00044 }
00045 else
00046 {
00047 pre = "";
00048 suf = "";
00049 }
00050 QStringList::ConstIterator sit = mails.begin();
00051 for (;sit!=mails.end();++sit)
00052 {
00053 contactLine=pre+(*sit)+suf;
00054 addressList->insertItem(contactLine);
00055 }
00056 }
00057 }
00058 if ( addressList->count() <= 0 )
00059 {
00060 #if 0
00061
00062 addressList->insertItem(
00063 tr( "There are no entries in the addressbook." ) );
00064 #endif
00065 addressList->setEnabled( false );
00066 okButton->setEnabled( false );
00067 }
00068 else
00069 {
00070
00071 }
00072 }
00073
00074 void AddressPicker::accept()
00075 {
00076 QListBoxItem *item = addressList->firstItem();
00077 QString names;
00078
00079 while ( item )
00080 {
00081 if ( item->selected() )
00082 names += item->text() + ", ";
00083 item = item->next();
00084 }
00085 names.replace( names.length() - 2, 2, "" );
00086
00087 if ( names.isEmpty() )
00088 {
00089 QMessageBox::information(this, tr("Error"), tr("<p>You have to select"
00090 " at least one address entry.</p>"), tr("Ok"));
00091 return;
00092 }
00093
00094 selectedNames = names;
00095 QDialog::accept();
00096 }
00097
00098 QString AddressPicker::getNames()
00099 {
00100 QString names = 0;
00101
00102 AddressPicker picker(0, 0, true);
00103
00104 int ret = QPEApplication::execDialog( &picker );
00105 if ( QDialog::Accepted == ret )
00106 {
00107 return picker.selectedNames;
00108 }
00109
00110 return 0;
00111 }
00112