summaryrefslogtreecommitdiff
path: root/noncore/net/mailit/writemail.cpp
Unidiff
Diffstat (limited to 'noncore/net/mailit/writemail.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mailit/writemail.cpp402
1 files changed, 0 insertions, 402 deletions
diff --git a/noncore/net/mailit/writemail.cpp b/noncore/net/mailit/writemail.cpp
deleted file mode 100644
index 26b9660..0000000
--- a/noncore/net/mailit/writemail.cpp
+++ b/dev/null
@@ -1,402 +0,0 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include <qmessagebox.h>
21#include <qwhatsthis.h>
22#include "writemail.h"
23#include <qpe/resource.h>
24
25WriteMail::WriteMail( QWidget* parent, const char* name, WFlags fl ):QMainWindow( parent, name, fl )
26{
27 showingAddressList = FALSE;
28 init();
29
30 addAtt = new AddAtt(0, "Add Attachments");
31}
32
33WriteMail::~WriteMail()
34{
35 delete addAtt;
36}
37
38void WriteMail::setAddressList(AddressList *list)
39{
40 AContact *cPtr;
41
42 addressList = list;
43
44 addressView->clear();
45 QList<AContact> *cListPtr = addressList->getContactList();
46 QListViewItem *item;
47 for (cPtr = cListPtr->first(); cPtr != 0; cPtr = cListPtr->next() ) {
48 item = new QListViewItem(addressView, cPtr->name, cPtr->email);
49 }
50}
51
52void WriteMail::init()
53{
54 setToolBarsMovable(FALSE);
55
56 bar = new QToolBar(this);
57 bar->setHorizontalStretchable( TRUE );
58
59 menu = new QMenuBar( bar );
60
61 mailMenu = new QPopupMenu(menu);
62 menu->insertItem( tr( "&Mail" ), mailMenu);
63 addMenu = new QPopupMenu(menu);
64 menu->insertItem( tr( "&Add" ), addMenu);
65
66 bar = new QToolBar(this);
67 attachButton = new QAction(tr("Attachment"), Resource::loadPixmap("mailit/attach"), QString::null, 0, this, 0);
68 attachButton->addTo(bar);
69 attachButton->addTo(addMenu);
70 connect( attachButton, SIGNAL( activated() ), this, SLOT( attachFile() ) );
71 attachButton->setWhatsThis(tr("Click here to attach files to your mail"));
72
73 confirmButton = new QAction(tr("Enque mail"), Resource::loadPixmap("OKButton"), QString::null, 0, this, 0);
74 confirmButton->addTo(bar);
75 confirmButton->addTo(mailMenu);
76 connect( confirmButton, SIGNAL( activated() ), this, SLOT( accept() ) );
77 confirmButton->setWhatsThis(tr("This button puts your mail in the send queue"));
78
79 newButton = new QAction(tr("New mail"), Resource::loadPixmap("new"), QString::null, 0, this, 0);
80 newButton->addTo(mailMenu);
81 connect( newButton, SIGNAL( activated() ), this, SLOT( newMail() ) );
82 newButton->setWhatsThis(tr("Click here to create a new mail"));
83
84 widget = new QWidget(this, "widget");
85 grid = new QGridLayout( widget );
86
87 recipientsBox = new QComboBox( FALSE, widget, "toLabel" );
88 recipientsBox->insertItem( tr( "To:" ) );
89 recipientsBox->insertItem( tr( "CC:" ) );
90 recipientsBox->setCurrentItem(0);
91 grid->addWidget( recipientsBox, 0, 0 );
92 connect(recipientsBox,SIGNAL(activated(int)),this, SLOT(changeRecipients(int)));
93
94 subjetLabel = new QLabel( widget, "subjetLabel" );
95 subjetLabel->setText( tr( "Subject:" ) );
96
97 grid->addWidget( subjetLabel, 1, 0 );
98
99 ToolButton13_2 = new QToolButton( widget, "ToolButton13_2" );
100 ToolButton13_2->setText( tr( "..." ) );
101 grid->addWidget( ToolButton13_2, 1, 2 );
102
103 subjectInput = new QLineEdit( widget, "subjectInput" );
104 grid->addWidget( subjectInput, 1, 1 );
105 QWhatsThis::add(subjectInput,QWidget::tr("The mail subject should be entered here"));
106
107 toInput = new QLineEdit( widget, "toInput" );
108 grid->addWidget( toInput, 0, 1 );
109 QWhatsThis::add(recipientsBox,QWidget::tr("Recipients can be entered here"));
110
111 ccInput = new QLineEdit( widget, "ccInput" );
112 ccInput->hide();
113 grid->addWidget( ccInput, 0, 1 );
114 QWhatsThis::add(ccInput,QWidget::tr("If you would like to send copies of your mail they can be entered here"));
115
116 addressButton = new QToolButton( widget, "addressButton" );
117 addressButton->setPixmap( Resource::loadPixmap("AddressBook") );
118 addressButton->setToggleButton(TRUE);
119 grid->addWidget( addressButton, 0, 2 );
120 connect(addressButton, SIGNAL(clicked()), this, SLOT(getAddress()) );
121 QWhatsThis::add(addressButton,QWidget::tr("This button opens the address selector with all mail adresses from your Opie addressbook"));
122
123 emailInput = new QMultiLineEdit( widget, "emailInput" );
124 grid->addMultiCellWidget( emailInput, 2, 2, 0, 2);
125 QWhatsThis::add(emailInput,QWidget::tr("Enter your mail text here"));
126
127 addressView = new QListView( widget, "addressView");
128 addressView->addColumn(tr("Name"));
129 addressView->addColumn(tr("EMail") );
130 addressView->setAllColumnsShowFocus(TRUE);
131 addressView->setMultiSelection(TRUE);
132 addressView->hide();
133 grid->addMultiCellWidget( addressView, 3, 3, 0, 2);
134 QWhatsThis::add(recipientsBox,QWidget::tr("Choose the recipients from this list"));
135
136 okButton = new QToolButton(bar, "ok");
137 okButton->setPixmap( Resource::loadPixmap("enter") );
138 okButton->hide();
139 connect(okButton, SIGNAL(clicked()), this, SLOT(addRecipients()) );
140 QWhatsThis::add(okButton,QWidget::tr("Queue your mail by clicking here"));
141
142 setCentralWidget(widget);
143}
144
145void WriteMail::reject()
146{
147 emit cancelMail();
148}
149
150void WriteMail::accept()
151{
152 QStringList attachedFiles, attachmentsType;
153 int idCount = 0;
154
155 if (toInput->text() == "")
156 {
157 QMessageBox::warning(this,tr("No recipient"), tr("Send mail to whom?"), tr("OK\n"));
158 return;
159 }
160
161 if (! getRecipients(false) )
162 {
163 QMessageBox::warning(this,tr("Incorrect recipient separator"),
164 tr("Recipients must be separated by ;\nand be valid emailaddresses"), tr("OK\n"));
165 return;
166 }
167
168 if ((ccInput->text()!="") && (! getRecipients(true) ))
169 {
170 QMessageBox::warning(this,tr("Incorrect carbon copy separator"),
171 tr("CC Recipients must be separated by ;\nand be valid emailaddresses"), tr("OK\n"));
172 return;
173 }
174
175 mail.subject = subjectInput->text();
176 mail.body = emailInput->text();
177 mail.sent = false;
178 mail.received = false;
179
180 mail.rawMail = "To: ";
181
182 for (QStringList::Iterator it = mail.recipients.begin();
183 it != mail.recipients.end(); ++it) {
184
185 mail.rawMail += (*it);
186 mail.rawMail += ",\n";
187 }
188
189 mail.rawMail.truncate(mail.rawMail.length()-2);
190
191 mail.rawMail += "\nCC: ";
192
193 for (QStringList::Iterator it = mail.carbonCopies.begin();
194 it != mail.carbonCopies.end(); ++it) {
195
196 mail.rawMail += (*it);
197 mail.rawMail += ",\n";
198 }
199
200 mail.rawMail += mail.from;
201 mail.rawMail += "\nSubject: ";
202 mail.rawMail += mail.subject;
203 mail.rawMail += "\n\n";
204
205 attachedFiles = addAtt->returnattachedFiles();
206 attachmentsType = addAtt->returnFileTypes();
207
208 QStringList::Iterator itType = attachmentsType.begin();
209
210 Enclosure e;
211 for ( QStringList::Iterator it = attachedFiles.begin(); it != attachedFiles.end(); ++it ) {
212 e.id = idCount;
213 e.originalName = (*it).latin1();
214 e.contentType = (*itType).latin1();
215 e.contentAttribute = (*itType).latin1();
216 e.saved = TRUE;
217 mail.addEnclosure(&e);
218
219 itType++;
220 idCount++;
221 }
222 mail.rawMail += mail.body;
223 mail.rawMail += "\n";
224 mail.rawMail += ".\n";
225 emit sendMailRequested(mail);
226 addAtt->clear();
227}
228
229void WriteMail::getAddress()
230{
231 showingAddressList = !showingAddressList;
232
233 if (showingAddressList) {
234 emailInput->hide();
235 addressView->show();
236 okButton->show();
237
238 } else {
239 addressView->hide();
240 okButton->hide();
241 emailInput->show();
242 }
243}
244
245void WriteMail::attachFile()
246{
247 addAtt->showMaximized();
248}
249
250void WriteMail::reply(Email replyMail, bool replyAll)
251{
252 int pos;
253 QString ccRecipients;
254
255 mail = replyMail;
256 mail.files.clear();
257
258 toInput->setText(mail.fromMail);
259
260 if (replyAll)
261 {
262 for (QStringList::Iterator it = mail.carbonCopies.begin();it != mail.carbonCopies.end(); ++it)
263 {
264 ccRecipients.append(*it);
265 ccRecipients.append(";");
266 }
267 ccRecipients.truncate(ccRecipients.length()-1); //no ; at the end
268 ccInput->setText(ccRecipients);
269 }
270 else ccInput->clear();
271
272 subjectInput->setText(tr("Re: ") + mail.subject);
273
274 QString citation=mail.fromMail;
275 citation.append(tr(" wrote on "));
276 citation.append(mail.date);
277 citation.append(":\n");
278
279
280 //mail.body.insert(0,tr("On"));
281 pos = 0;
282 mail.body.insert(pos, ">");
283 while (pos != -1) {
284 pos = mail.body.find('\n', pos);
285 if (pos != -1)
286 mail.body.insert(++pos, ">");
287 }
288 mail.body.insert(0,citation);
289 emailInput->setText(mail.body);
290}
291
292void WriteMail::forward(Email forwMail)
293{
294 // int pos=0;
295
296 QString fwdBody=tr("======forwarded message from ");
297 fwdBody.append(forwMail.fromMail);
298 fwdBody.append(tr(" starts======\n\n"));
299
300 mail=forwMail;
301 toInput->setText("");
302 ccInput->setText("");
303 subjectInput->setText(tr("FWD: ") + mail.subject);
304
305 fwdBody+=mail.body;
306 fwdBody+=QString(tr("======end of forwarded message======\n\n"));
307
308 emailInput->setText(fwdBody);
309}
310
311bool WriteMail::getRecipients(bool ccField)
312{
313 QString str, temp;
314 int pos = 0;
315
316 if (ccField)
317 {
318 mail.carbonCopies.clear();
319 temp = ccInput->text();
320 }
321 else
322 {
323 mail.recipients.clear();
324 temp=toInput->text() ;
325 }
326
327 while ( (pos = temp.find(';')) != -1) {
328 str = temp.left(pos).stripWhiteSpace();
329 temp = temp.right(temp.length() - (pos + 1));
330 if ( str.find('@') == -1)
331 return false;
332 ccField ? mail.carbonCopies.append(str) : mail.recipients.append(str);
333 //addressList->addContact(str, "");
334 }
335 temp = temp.stripWhiteSpace();
336 if ( temp.find('@') == -1)
337 return false;
338 ccField ? mail.carbonCopies.append(temp) : mail.recipients.append(temp);
339 //addressList->addContact(temp, "");
340
341 return TRUE;
342}
343
344void WriteMail::addRecipients()
345{
346 toInput->isVisible() ? addRecipients(false) : addRecipients(true);
347}
348
349void WriteMail::addRecipients(bool ccField)
350{
351 QString recipients = "";
352
353 mail.recipients.clear();
354
355 QListViewItem *item = addressView->firstChild();
356 while (item != NULL) {
357 if ( item->isSelected() ) {
358 if (recipients == "") {
359 recipients = item->text(1);
360 } else {
361 recipients += "; " + item->text(1);
362 }
363 }
364 item = item->nextSibling();
365 }
366
367 ccField ? ccInput->setText(recipients):toInput->setText(recipients);
368
369 addressView->hide();
370 okButton->hide();
371 emailInput->show();
372 addressButton->setOn(FALSE);
373 showingAddressList = !showingAddressList;
374}
375
376void WriteMail::changeRecipients(int selection)
377{
378 if (selection==0)
379 {
380 toInput->show();
381 ccInput->hide();
382 }
383 else if (selection==1)
384 {
385 toInput->hide();
386 ccInput->show();
387 }
388}
389
390void WriteMail::setRecipient(const QString &recipient)
391{
392 toInput->setText(recipient);
393}
394
395void WriteMail::newMail()
396{
397 toInput->clear();
398 ccInput->clear();
399 subjectInput->clear();
400 emailInput->clear();
401 setAddressList(addressList);
402}