author | llornkcor <llornkcor> | 2003-04-06 17:45:00 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2003-04-06 17:45:00 (UTC) |
commit | 70b1ff1a3f134d75d1539f269d52b34e6762684d (patch) (unidiff) | |
tree | 28c1b3d0c03e8c0188f014dfe094645d1ddfef5f /noncore/net/mailit/writemail.cpp | |
parent | 75e8f29020e267d1013a79839831035073b4eeae (diff) | |
download | opie-70b1ff1a3f134d75d1539f269d52b34e6762684d.zip opie-70b1ff1a3f134d75d1539f269d52b34e6762684d.tar.gz opie-70b1ff1a3f134d75d1539f269d52b34e6762684d.tar.bz2 |
move malit to head again, since it is working
Diffstat (limited to 'noncore/net/mailit/writemail.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/mailit/writemail.cpp | 299 |
1 files changed, 299 insertions, 0 deletions
diff --git a/noncore/net/mailit/writemail.cpp b/noncore/net/mailit/writemail.cpp new file mode 100644 index 0000000..1a7185e --- a/dev/null +++ b/noncore/net/mailit/writemail.cpp | |||
@@ -0,0 +1,299 @@ | |||
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 "writemail.h" | ||
22 | #include "resource.h" | ||
23 | |||
24 | WriteMail::WriteMail( QWidget* parent, const char* name, WFlags fl ) | ||
25 | : QMainWindow( parent, name, fl ) | ||
26 | { | ||
27 | showingAddressList = FALSE; | ||
28 | init(); | ||
29 | |||
30 | addAtt = new AddAtt(0, "Add Attatchments"); | ||
31 | } | ||
32 | |||
33 | WriteMail::~WriteMail() | ||
34 | { | ||
35 | delete addAtt; | ||
36 | } | ||
37 | |||
38 | void WriteMail::setAddressList(AddressList *list) | ||
39 | { | ||
40 | Contact *cPtr; | ||
41 | |||
42 | addressList = list; | ||
43 | |||
44 | addressView->clear(); | ||
45 | QList<Contact> *cListPtr = addressList->getContactList(); | ||
46 | QListViewItem *item; | ||
47 | for (cPtr = cListPtr->first(); cPtr != 0; cPtr = cListPtr->next() ) { | ||
48 | item = new QListViewItem(addressView, cPtr->email, cPtr->name); | ||
49 | } | ||
50 | } | ||
51 | |||
52 | void 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 | attatchButton = new QAction(tr("Attatchment"), Resource::loadPixmap("fileopen"), QString::null, 0, this, 0); | ||
68 | attatchButton->addTo(bar); | ||
69 | attatchButton->addTo(addMenu); | ||
70 | connect( attatchButton, SIGNAL( activated() ), this, SLOT( attatchFile() ) ); | ||
71 | |||
72 | confirmButton = new QAction(tr("Enque mail"), Resource::loadPixmap("OKButton"), QString::null, 0, this, 0); | ||
73 | confirmButton->addTo(bar); | ||
74 | confirmButton->addTo(mailMenu); | ||
75 | connect( confirmButton, SIGNAL( activated() ), this, SLOT( accept() ) ); | ||
76 | |||
77 | newButton = new QAction(tr("New mail"), Resource::loadPixmap("new"), QString::null, 0, this, 0); | ||
78 | newButton->addTo(mailMenu); | ||
79 | connect( newButton, SIGNAL( activated() ), this, SLOT( newMail() ) ); | ||
80 | |||
81 | widget = new QWidget(this, "widget"); | ||
82 | grid = new QGridLayout( widget ); | ||
83 | |||
84 | recipientsBox = new QComboBox( FALSE, widget, "toLabel" ); | ||
85 | recipientsBox->insertItem( tr( "To:" ) ); | ||
86 | recipientsBox->insertItem( tr( "CC:" ) ); | ||
87 | recipientsBox->setCurrentItem(0); | ||
88 | grid->addWidget( recipientsBox, 0, 0 ); | ||
89 | |||
90 | subjetLabel = new QLabel( widget, "subjetLabel" ); | ||
91 | subjetLabel->setText( tr( "Subject:" ) ); | ||
92 | |||
93 | grid->addWidget( subjetLabel, 1, 0 ); | ||
94 | |||
95 | ToolButton13_2 = new QToolButton( widget, "ToolButton13_2" ); | ||
96 | ToolButton13_2->setText( tr( "..." ) ); | ||
97 | grid->addWidget( ToolButton13_2, 1, 2 ); | ||
98 | |||
99 | subjectInput = new QLineEdit( widget, "subjectInput" ); | ||
100 | grid->addWidget( subjectInput, 1, 1 ); | ||
101 | |||
102 | toInput = new QLineEdit( widget, "toInput" ); | ||
103 | grid->addWidget( toInput, 0, 1 ); | ||
104 | |||
105 | addressButton = new QToolButton( widget, "addressButton" ); | ||
106 | addressButton->setPixmap( Resource::loadPixmap("AddressBook") ); | ||
107 | addressButton->setToggleButton(TRUE); | ||
108 | grid->addWidget( addressButton, 0, 2 ); | ||
109 | connect(addressButton, SIGNAL(clicked()), this, SLOT(getAddress()) ); | ||
110 | |||
111 | emailInput = new QMultiLineEdit( widget, "emailInput" ); | ||
112 | grid->addMultiCellWidget( emailInput, 2, 2, 0, 2); | ||
113 | |||
114 | addressView = new QListView( widget, "addressView"); | ||
115 | addressView->addColumn("Email"); | ||
116 | addressView->addColumn("Name"); | ||
117 | addressView->setAllColumnsShowFocus(TRUE); | ||
118 | addressView->setMultiSelection(TRUE); | ||
119 | addressView->hide(); | ||
120 | grid->addMultiCellWidget( addressView, 3, 3, 0, 2); | ||
121 | |||
122 | okButton = new QToolButton(bar, "ok"); | ||
123 | okButton->setPixmap( Resource::loadPixmap("enter") ); | ||
124 | okButton->hide(); | ||
125 | connect(okButton, SIGNAL(clicked()), this, SLOT(addRecipients()) ); | ||
126 | |||
127 | setCentralWidget(widget); | ||
128 | } | ||
129 | |||
130 | void WriteMail::reject() | ||
131 | { | ||
132 | emit cancelMail(); | ||
133 | } | ||
134 | |||
135 | // need to insert date | ||
136 | void WriteMail::accept() | ||
137 | { | ||
138 | QStringList attatchedFiles, attatchmentsType; | ||
139 | int idCount = 0; | ||
140 | |||
141 | if (toInput->text() == "") { | ||
142 | QMessageBox::warning(this,"No recipient", "Send mail to whom?", "OK\n"); | ||
143 | return; | ||
144 | } | ||
145 | if (! getRecipients() ) { | ||
146 | QMessageBox::warning(this,"Incorrect recipient separator", | ||
147 | "Recipients must be separated by ;\nand be valid emailaddresses", "OK\n"); | ||
148 | return; | ||
149 | } | ||
150 | mail.subject = subjectInput->text(); | ||
151 | mail.body = emailInput->text(); | ||
152 | mail.sent = false; | ||
153 | mail.received = false; | ||
154 | mail.rawMail = "To: "; | ||
155 | |||
156 | for (QStringList::Iterator it = mail.recipients.begin(); | ||
157 | it != mail.recipients.end(); ++it) { | ||
158 | |||
159 | mail.rawMail += (*it); | ||
160 | mail.rawMail += ",\n"; | ||
161 | } | ||
162 | mail.rawMail.truncate(mail.rawMail.length()-2); | ||
163 | mail.rawMail += mail.from; | ||
164 | mail.rawMail += "\nSubject: "; | ||
165 | mail.rawMail += mail.subject; | ||
166 | mail.rawMail += "\n\n"; | ||
167 | |||
168 | attatchedFiles = addAtt->returnAttatchedFiles(); | ||
169 | attatchmentsType = addAtt->returnFileTypes(); | ||
170 | |||
171 | QStringList::Iterator itType = attatchmentsType.begin(); | ||
172 | |||
173 | Enclosure e; | ||
174 | for ( QStringList::Iterator it = attatchedFiles.begin(); | ||
175 | it != attatchedFiles.end(); ++it ) { | ||
176 | |||
177 | e.id = idCount; | ||
178 | e.originalName = (*it).latin1(); | ||
179 | e.contentType = (*itType).latin1(); | ||
180 | e.contentAttribute = (*itType).latin1(); | ||
181 | e.saved = TRUE; | ||
182 | mail.addEnclosure(&e); | ||
183 | |||
184 | itType++; | ||
185 | idCount++; | ||
186 | } | ||
187 | mail.rawMail += mail.body; | ||
188 | mail.rawMail += "\n"; | ||
189 | mail.rawMail += ".\n"; | ||
190 | emit sendMailRequested(mail); | ||
191 | addAtt->clear(); | ||
192 | } | ||
193 | |||
194 | void WriteMail::getAddress() | ||
195 | { | ||
196 | showingAddressList = !showingAddressList; | ||
197 | |||
198 | if (showingAddressList) { | ||
199 | emailInput->hide(); | ||
200 | addressView->show(); | ||
201 | okButton->show(); | ||
202 | |||
203 | } else { | ||
204 | addressView->hide(); | ||
205 | okButton->hide(); | ||
206 | emailInput->show(); | ||
207 | } | ||
208 | } | ||
209 | |||
210 | void WriteMail::attatchFile() | ||
211 | { | ||
212 | addAtt->showMaximized(); | ||
213 | } | ||
214 | |||
215 | void WriteMail::reply(Email replyMail) | ||
216 | { | ||
217 | int pos; | ||
218 | |||
219 | mail = replyMail; | ||
220 | mail.files.clear(); | ||
221 | |||
222 | toInput->setText(mail.fromMail); | ||
223 | subjectInput->setText("Re: " + mail.subject); | ||
224 | |||
225 | pos = 0; | ||
226 | mail.body.insert(pos, ">>"); | ||
227 | while (pos != -1) { | ||
228 | pos = mail.body.find('\n', pos); | ||
229 | if (pos != -1) | ||
230 | mail.body.insert(++pos, ">>"); | ||
231 | } | ||
232 | |||
233 | emailInput->setText(mail.body); | ||
234 | } | ||
235 | |||
236 | bool WriteMail::getRecipients() | ||
237 | { | ||
238 | QString str, temp; | ||
239 | int pos = 0; | ||
240 | |||
241 | mail.recipients.clear(); | ||
242 | |||
243 | temp = toInput->text(); | ||
244 | while ( (pos = temp.find(';')) != -1) { | ||
245 | str = temp.left(pos).stripWhiteSpace(); | ||
246 | temp = temp.right(temp.length() - (pos + 1)); | ||
247 | if ( str.find('@') == -1) | ||
248 | return false; | ||
249 | mail.recipients.append(str); | ||
250 | addressList->addContact(str, ""); | ||
251 | } | ||
252 | temp = temp.stripWhiteSpace(); | ||
253 | if ( temp.find('@') == -1) | ||
254 | return false; | ||
255 | mail.recipients.append(temp); | ||
256 | addressList->addContact(temp, ""); | ||
257 | |||
258 | return TRUE; | ||
259 | } | ||
260 | |||
261 | |||
262 | void WriteMail::addRecipients() | ||
263 | { | ||
264 | QString recipients = ""; | ||
265 | |||
266 | mail.recipients.clear(); | ||
267 | QListViewItem *item = addressView->firstChild(); | ||
268 | while (item != NULL) { | ||
269 | if ( item->isSelected() ) { | ||
270 | if (recipients == "") { | ||
271 | recipients = item->text(0); | ||
272 | } else { | ||
273 | recipients += "; " + item->text(0); | ||
274 | } | ||
275 | } | ||
276 | item = item->nextSibling(); | ||
277 | } | ||
278 | toInput->setText(recipients); | ||
279 | |||
280 | addressView->hide(); | ||
281 | okButton->hide(); | ||
282 | emailInput->show(); | ||
283 | addressButton->setOn(FALSE); | ||
284 | showingAddressList = !showingAddressList; | ||
285 | } | ||
286 | |||
287 | void WriteMail::setRecipient(const QString &recipient) | ||
288 | { | ||
289 | toInput->setText(recipient); | ||
290 | } | ||
291 | |||
292 | void WriteMail::newMail() | ||
293 | { | ||
294 | toInput->clear(); | ||
295 | subjectInput->clear(); | ||
296 | emailInput->clear(); | ||
297 | //to clear selected | ||
298 | setAddressList(addressList); | ||
299 | } | ||