00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <qmessagebox.h>
00021 #include <qwhatsthis.h>
00022 #include "writemail.h"
00023 #include <qpe/resource.h>
00024
00025 WriteMail::WriteMail( QWidget* parent, const char* name, WFlags fl ):QMainWindow( parent, name, fl )
00026 {
00027 showingAddressList = FALSE;
00028 init();
00029
00030 addAtt = new AddAtt(0, "Add Attachments");
00031 }
00032
00033 WriteMail::~WriteMail()
00034 {
00035 delete addAtt;
00036 }
00037
00038 void WriteMail::setAddressList(AddressList *list)
00039 {
00040 AContact *cPtr;
00041
00042 addressList = list;
00043
00044 addressView->clear();
00045 QList<AContact> *cListPtr = addressList->getContactList();
00046 QListViewItem *item;
00047 for (cPtr = cListPtr->first(); cPtr != 0; cPtr = cListPtr->next() ) {
00048 item = new QListViewItem(addressView, cPtr->name, cPtr->email);
00049 }
00050 }
00051
00052 void WriteMail::init()
00053 {
00054 setToolBarsMovable(FALSE);
00055
00056 bar = new QToolBar(this);
00057 bar->setHorizontalStretchable( TRUE );
00058
00059 menu = new QMenuBar( bar );
00060
00061 mailMenu = new QPopupMenu(menu);
00062 menu->insertItem( tr( "&Mail" ), mailMenu);
00063 addMenu = new QPopupMenu(menu);
00064 menu->insertItem( tr( "&Add" ), addMenu);
00065
00066 bar = new QToolBar(this);
00067 attachButton = new QAction(tr("Attachment"), Resource::loadPixmap("mailit/attach"), QString::null, 0, this, 0);
00068 attachButton->addTo(bar);
00069 attachButton->addTo(addMenu);
00070 connect( attachButton, SIGNAL( activated() ), this, SLOT( attachFile() ) );
00071 attachButton->setWhatsThis(tr("Click here to attach files to your mail"));
00072
00073 confirmButton = new QAction(tr("Enque mail"), Resource::loadPixmap("OKButton"), QString::null, 0, this, 0);
00074 confirmButton->addTo(bar);
00075 confirmButton->addTo(mailMenu);
00076 connect( confirmButton, SIGNAL( activated() ), this, SLOT( accept() ) );
00077 confirmButton->setWhatsThis(tr("This button puts your mail in the send queue"));
00078
00079 newButton = new QAction(tr("New mail"), Resource::loadPixmap("new"), QString::null, 0, this, 0);
00080 newButton->addTo(mailMenu);
00081 connect( newButton, SIGNAL( activated() ), this, SLOT( newMail() ) );
00082 newButton->setWhatsThis(tr("Click here to create a new mail"));
00083
00084 widget = new QWidget(this, "widget");
00085 grid = new QGridLayout( widget );
00086
00087 recipientsBox = new QComboBox( FALSE, widget, "toLabel" );
00088 recipientsBox->insertItem( tr( "To:" ) );
00089 recipientsBox->insertItem( tr( "CC:" ) );
00090 recipientsBox->setCurrentItem(0);
00091 grid->addWidget( recipientsBox, 0, 0 );
00092 connect(recipientsBox,SIGNAL(activated(int)),this, SLOT(changeRecipients(int)));
00093
00094 subjetLabel = new QLabel( widget, "subjetLabel" );
00095 subjetLabel->setText( tr( "Subject:" ) );
00096
00097 grid->addWidget( subjetLabel, 1, 0 );
00098
00099 ToolButton13_2 = new QToolButton( widget, "ToolButton13_2" );
00100 ToolButton13_2->setText( tr( "..." ) );
00101 grid->addWidget( ToolButton13_2, 1, 2 );
00102
00103 subjectInput = new QLineEdit( widget, "subjectInput" );
00104 grid->addWidget( subjectInput, 1, 1 );
00105 QWhatsThis::add(subjectInput,QWidget::tr("The mail subject should be entered here"));
00106
00107 toInput = new QLineEdit( widget, "toInput" );
00108 grid->addWidget( toInput, 0, 1 );
00109 QWhatsThis::add(recipientsBox,QWidget::tr("Recipients can be entered here"));
00110
00111 ccInput = new QLineEdit( widget, "ccInput" );
00112 ccInput->hide();
00113 grid->addWidget( ccInput, 0, 1 );
00114 QWhatsThis::add(ccInput,QWidget::tr("If you would like to send copies of your mail they can be entered here"));
00115
00116 addressButton = new QToolButton( widget, "addressButton" );
00117 addressButton->setPixmap( Resource::loadPixmap("AddressBook") );
00118 addressButton->setToggleButton(TRUE);
00119 grid->addWidget( addressButton, 0, 2 );
00120 connect(addressButton, SIGNAL(clicked()), this, SLOT(getAddress()) );
00121 QWhatsThis::add(addressButton,QWidget::tr("This button opens the address selector with all mail adresses from your Opie addressbook"));
00122
00123 emailInput = new QMultiLineEdit( widget, "emailInput" );
00124 grid->addMultiCellWidget( emailInput, 2, 2, 0, 2);
00125 QWhatsThis::add(emailInput,QWidget::tr("Enter your mail text here"));
00126
00127 addressView = new QListView( widget, "addressView");
00128 addressView->addColumn(tr("Name"));
00129 addressView->addColumn(tr("EMail") );
00130 addressView->setAllColumnsShowFocus(TRUE);
00131 addressView->setMultiSelection(TRUE);
00132 addressView->hide();
00133 grid->addMultiCellWidget( addressView, 3, 3, 0, 2);
00134 QWhatsThis::add(recipientsBox,QWidget::tr("Choose the recipients from this list"));
00135
00136 okButton = new QToolButton(bar, "ok");
00137 okButton->setPixmap( Resource::loadPixmap("enter") );
00138 okButton->hide();
00139 connect(okButton, SIGNAL(clicked()), this, SLOT(addRecipients()) );
00140 QWhatsThis::add(okButton,QWidget::tr("Queue your mail by clicking here"));
00141
00142 setCentralWidget(widget);
00143 }
00144
00145 void WriteMail::reject()
00146 {
00147 emit cancelMail();
00148 }
00149
00150 void WriteMail::accept()
00151 {
00152 QStringList attachedFiles, attachmentsType;
00153 int idCount = 0;
00154
00155 if (toInput->text() == "")
00156 {
00157 QMessageBox::warning(this,tr("No recipient"), tr("Send mail to whom?"), tr("OK\n"));
00158 return;
00159 }
00160
00161 if (! getRecipients(false) )
00162 {
00163 QMessageBox::warning(this,tr("Incorrect recipient separator"),
00164 tr("Recipients must be separated by ;\nand be valid emailaddresses"), tr("OK\n"));
00165 return;
00166 }
00167
00168 if ((ccInput->text()!="") && (! getRecipients(true) ))
00169 {
00170 QMessageBox::warning(this,tr("Incorrect carbon copy separator"),
00171 tr("CC Recipients must be separated by ;\nand be valid emailaddresses"), tr("OK\n"));
00172 return;
00173 }
00174
00175 mail.subject = subjectInput->text();
00176 mail.body = emailInput->text();
00177 mail.sent = false;
00178 mail.received = false;
00179
00180 mail.rawMail = "To: ";
00181
00182 for (QStringList::Iterator it = mail.recipients.begin();
00183 it != mail.recipients.end(); ++it) {
00184
00185 mail.rawMail += (*it);
00186 mail.rawMail += ",\n";
00187 }
00188
00189 mail.rawMail.truncate(mail.rawMail.length()-2);
00190
00191 mail.rawMail += "\nCC: ";
00192
00193 for (QStringList::Iterator it = mail.carbonCopies.begin();
00194 it != mail.carbonCopies.end(); ++it) {
00195
00196 mail.rawMail += (*it);
00197 mail.rawMail += ",\n";
00198 }
00199
00200 mail.rawMail += mail.from;
00201 mail.rawMail += "\nSubject: ";
00202 mail.rawMail += mail.subject;
00203 mail.rawMail += "\n\n";
00204
00205 attachedFiles = addAtt->returnattachedFiles();
00206 attachmentsType = addAtt->returnFileTypes();
00207
00208 QStringList::Iterator itType = attachmentsType.begin();
00209
00210 Enclosure e;
00211 for ( QStringList::Iterator it = attachedFiles.begin(); it != attachedFiles.end(); ++it ) {
00212 e.id = idCount;
00213 e.originalName = (*it).latin1();
00214 e.contentType = (*itType).latin1();
00215 e.contentAttribute = (*itType).latin1();
00216 e.saved = TRUE;
00217 mail.addEnclosure(&e);
00218
00219 itType++;
00220 idCount++;
00221 }
00222 mail.rawMail += mail.body;
00223 mail.rawMail += "\n";
00224 mail.rawMail += ".\n";
00225 emit sendMailRequested(mail);
00226 addAtt->clear();
00227 }
00228
00229 void WriteMail::getAddress()
00230 {
00231 showingAddressList = !showingAddressList;
00232
00233 if (showingAddressList) {
00234 emailInput->hide();
00235 addressView->show();
00236 okButton->show();
00237
00238 } else {
00239 addressView->hide();
00240 okButton->hide();
00241 emailInput->show();
00242 }
00243 }
00244
00245 void WriteMail::attachFile()
00246 {
00247 addAtt->showMaximized();
00248 }
00249
00250 void WriteMail::reply(Email replyMail, bool replyAll)
00251 {
00252 int pos;
00253 QString ccRecipients;
00254
00255 mail = replyMail;
00256 mail.files.clear();
00257
00258 toInput->setText(mail.fromMail);
00259
00260 if (replyAll)
00261 {
00262 for (QStringList::Iterator it = mail.carbonCopies.begin();it != mail.carbonCopies.end(); ++it)
00263 {
00264 ccRecipients.append(*it);
00265 ccRecipients.append(";");
00266 }
00267 ccRecipients.truncate(ccRecipients.length()-1);
00268 ccInput->setText(ccRecipients);
00269 }
00270 else ccInput->clear();
00271
00272 subjectInput->setText(tr("Re: ") + mail.subject);
00273
00274 QString citation=mail.fromMail;
00275 citation.append(tr(" wrote on "));
00276 citation.append(mail.date);
00277 citation.append(":\n");
00278
00279
00280
00281 pos = 0;
00282 mail.body.insert(pos, ">");
00283 while (pos != -1) {
00284 pos = mail.body.find('\n', pos);
00285 if (pos != -1)
00286 mail.body.insert(++pos, ">");
00287 }
00288 mail.body.insert(0,citation);
00289 emailInput->setText(mail.body);
00290 }
00291
00292 void WriteMail::forward(Email forwMail)
00293 {
00294
00295
00296 QString fwdBody=tr("======forwarded message from ");
00297 fwdBody.append(forwMail.fromMail);
00298 fwdBody.append(tr(" starts======\n\n"));
00299
00300 mail=forwMail;
00301 toInput->setText("");
00302 ccInput->setText("");
00303 subjectInput->setText(tr("FWD: ") + mail.subject);
00304
00305 fwdBody+=mail.body;
00306 fwdBody+=QString(tr("======end of forwarded message======\n\n"));
00307
00308 emailInput->setText(fwdBody);
00309 }
00310
00311 bool WriteMail::getRecipients(bool ccField)
00312 {
00313 QString str, temp;
00314 int pos = 0;
00315
00316 if (ccField)
00317 {
00318 mail.carbonCopies.clear();
00319 temp = ccInput->text();
00320 }
00321 else
00322 {
00323 mail.recipients.clear();
00324 temp=toInput->text() ;
00325 }
00326
00327 while ( (pos = temp.find(';')) != -1) {
00328 str = temp.left(pos).stripWhiteSpace();
00329 temp = temp.right(temp.length() - (pos + 1));
00330 if ( str.find('@') == -1)
00331 return false;
00332 ccField ? mail.carbonCopies.append(str) : mail.recipients.append(str);
00333
00334 }
00335 temp = temp.stripWhiteSpace();
00336 if ( temp.find('@') == -1)
00337 return false;
00338 ccField ? mail.carbonCopies.append(temp) : mail.recipients.append(temp);
00339
00340
00341 return TRUE;
00342 }
00343
00344 void WriteMail::addRecipients()
00345 {
00346 toInput->isVisible() ? addRecipients(false) : addRecipients(true);
00347 }
00348
00349 void WriteMail::addRecipients(bool ccField)
00350 {
00351 QString recipients = "";
00352
00353 mail.recipients.clear();
00354
00355 QListViewItem *item = addressView->firstChild();
00356 while (item != NULL) {
00357 if ( item->isSelected() ) {
00358 if (recipients == "") {
00359 recipients = item->text(1);
00360 } else {
00361 recipients += "; " + item->text(1);
00362 }
00363 }
00364 item = item->nextSibling();
00365 }
00366
00367 ccField ? ccInput->setText(recipients):toInput->setText(recipients);
00368
00369 addressView->hide();
00370 okButton->hide();
00371 emailInput->show();
00372 addressButton->setOn(FALSE);
00373 showingAddressList = !showingAddressList;
00374 }
00375
00376 void WriteMail::changeRecipients(int selection)
00377 {
00378 if (selection==0)
00379 {
00380 toInput->show();
00381 ccInput->hide();
00382 }
00383 else if (selection==1)
00384 {
00385 toInput->hide();
00386 ccInput->show();
00387 }
00388 }
00389
00390 void WriteMail::setRecipient(const QString &recipient)
00391 {
00392 toInput->setText(recipient);
00393 }
00394
00395 void WriteMail::newMail()
00396 {
00397 toInput->clear();
00398 ccInput->clear();
00399 subjectInput->clear();
00400 emailInput->clear();
00401 setAddressList(addressList);
00402 }